/*************************************************************************
 * Source Id :
 *
 * $Id: cache.h,v 1.2 2001/04/19 21:13:25 georgetasker Exp $
 *-------------------------------------------------------------------------
 * Project Notes :
 *
 *  Diamond Base
 *  ============
 *      A solid database implementation, spurred on by the continuing
 *  Metal (Lead) Base saga.
 *
 *  Project Team :
 *        A. Davison
 *        K. Lentin
 *        D. Platt
 *
 *	Project Commenced : 05-02-1993
 *
 *-------------------------------------------------------------------------
 *  Module Notes :
 *
 *  Record caching for dbobj
 *
 *
 *  Original Author : Kev
 *
 **************************************************************************/

#ifndef __DB_CACHE_H__
#define __DB_CACHE_H__

#include <diamond/defs.h>

const int DEF_CACHE_SIZE = 10;

// A block of the cache has an id number and block of data

struct cacheBlock {
	char*	block;
	int32	id;
};

// The cache class itself

class cache {
	cacheBlock*	data;		// The array of blocks
	int32		cacheSize;	// The number of blocks to cache
	int32		blockSize;	// How big each block is
	int32		curSize;	// How many we have currently
	int32		attempts;	// The stats
	int32		hits;
	int32		writes;
	int32		dispose;

public:
				cache(const int32 bSize, const int32 cSize = DEF_CACHE_SIZE);
				cache(void);
				~cache();
	const char*	verStr(void) const;
	void		createCache(const int32 bSize, const int32 cSize = DEF_CACHE_SIZE);
	void		freeCache(void);
	void		flushCache(void);
	bool		inCache(const int32 id) const;
	int32		whereCache(const int32 id) const;
	bool		getCache(char* where, const int32 id);
	void		putCache(char* where, const int32 id);
	void		stats(void) const;
};

#endif

//////////////////////////////////////////////////////////////////////////
// Revision History:
//
// $Log: cache.h,v $
// Revision 1.2  2001/04/19 21:13:25  georgetasker
// cygwin compilation fixes
//
// Revision 1.1  2001/04/03 20:10:25  aleksandras
// big one 3.1 (comments later)
//
// Revision 1.10  1996/02/01  22:44:56  dmb
// int32.
//
// Revision 1.9  1994/03/17  04:34:45  kevinl
// Added flushCache.
//
// Revision 1.8  1994/02/03  05:50:31  kevinl
// Moved include files to diamond/ and fixed HAVE_MALLOC_H
//
// Revision 1.7  1993/12/23  22:58:48  kevinl
// dbErr uses dbString, autoconf stuff, moved logs, added const and size_t
//
// Revision 1.6  1993/06/23  05:21:22  kevinl
// Mallocs are now in angular brackets
//
// Revision 1.5  1993/05/11  14:44:50  kevinl
// Added version number output
//
// Revision 1.4  1993/05/03  01:33:55  kevinl
// whereCache not inline
//
// Revision 1.3  1993/04/25  10:11:47  kevinl
// Added freeCache to allow destructing/reconstructing properly (in case)
// Comments!
//
// Revision 1.2  1993/04/09  13:00:29  kevinl
// Stats can be called from diaRel now.
//
// Revision 1.1  1993/04/05  00:00:08  kevinl
// Initial revision
//////////////////////////////////////////////////////////////////////////
