Index: ossp-pkg/cache/cache.c RCS File: /v/ossp/cvs/ossp-pkg/cache/cache.c,v rcsdiff -q -kk '-r1.1' '-r1.2' -u '/v/ossp/cvs/ossp-pkg/cache/cache.c,v' 2>/dev/null --- cache.c 2002/01/09 10:44:28 1.1 +++ cache.c 2002/02/16 12:57:57 1.2 @@ -47,3 +47,60 @@ #define TRUE (!FALSE) #endif +/* forward declarations */ +struct cache_st; +struct cache_obj_st; + +/* type definitions */ +typedef struct cache_obj_st cache_obj_t; + +/* support for relative pointers (offset pointers) */ +typedef long op_t; +#define VP2OP(bp,vp) \ + (long)(((char *)(vp))-((char *)(bp))) +#define OP2VP(bp,op) \ + (void *)(((char *)(bp))+((char *)(op))) + +/* definition: top-level cache structure */ +struct cache_st { + /* top level access pointers */ + op_t opHash; /* pointer to hash table */ + op_t opObjMRU; /* pointer to MRU object */ + op_t opObjLRU; /* pointer to LRU object */ + op_t opObjEmpty; /* pointer to empty object */ + + /* information */ + int bExpireReset; /* whether expire resets on each access or is absolute */ + int tExpireReset; /* the optional expire reset time */ + + /* sub-structure information */ + op_t opKeyIndex; /* base address of key bucket index */ + op_t opKeyBuckets; /* base address of key bucket pool */ + int nKeyBuckets; /* number of buckets in key bucket pool */ + op_t opValIndex; /* base address of key bucket index */ + op_t opValBuckets; /* base address of value bucket pool */ + int nValBuckets; /* number of buckets in value bucket pool */ + + /* statistics */ + long nInserts; + long nLookups; + long nLookupsSuccess; + long nRemoves; + + /* callbacks */ + /* ... */ +}; + +/* definition: cache object */ +struct cache_obj_st { + int bUsed; /* used in an ongoing iteration */ + op_t opHashNext; /* next object in hash table collision chain */ + op_t opQueuePrev; /* previous object in LRU queue */ + op_t opQueueNext; /* next object in LRU queue */ + op_t opKey; /* pointer to first key segment in key index */ + size_t nKey; /* size of key in bytes */ + op_t opVal; /* pointer to first value segment in value index */ + size_t nVal; /* size of value in bytes */ + time_t tExpire; /* expire time of object */ +}; + Index: ossp-pkg/cache/cache.h RCS File: /v/ossp/cvs/ossp-pkg/cache/cache.h,v rcsdiff -q -kk '-r1.1' '-r1.2' -u '/v/ossp/cvs/ossp-pkg/cache/cache.h,v' 2>/dev/null --- cache.h 2002/01/09 10:44:28 1.1 +++ cache.h 2002/02/16 12:57:58 1.2 @@ -31,5 +31,58 @@ #ifndef __CACHE_H__ #define __CACHE_H__ +struct cache_st; +typedef cache_st cache_t; + +typedef enum { + CACHE_OK = 0, + CACHE_ERR_INVAL, + CACHE_ERR_SYS +} cache_rc_t; + +typedef enum { + CACHE_SET, + CACHE_GET, +} cache_config_t; + +typedef enum { + CACHE_ST_MAXKEY, + CACHE_CB_MUTEXACQUIRE, + CACHE_CB_MUTEXRELEASE, + CACHE_CB_OBJECTREMOVE, +} cache_param_t; + +typedef enum { + CACHE_INPLACE, /* re-arrange segments internally */ + CACHE_COPYOUT, /* copy as serialized object into new buffer */ + CACHE_MOVEOUT, /* move as serialized object into existing buffer */ +} cache_fetch_t; + +typedef struct { + void *ptr; + size_t len; +} cache_blob_t; + +cache_rc_t cache_attach (cache_t **cache, void *memptr, size_t memlen, size_t keyseg, size_t valseg); +cache_rc_t cache_config (cache_t *cache, cache_config_t mode, cache_param_t id, ...); +cache_rc_t cache_detach (cache_t *cache); + +cache_rc_t cache_insert (cache_t *cache, cache_blob_t key, cache_blob_t val, time_t now, time_t expire); +cache_rc_t cache_lookup (cache_t *cache, cache_blob_t key, cache_obj_t **obj, time_t now); +cache_rc_t cache_remove (cache_t *cache, cache_blob_t key); + +cache_rc_t cache_obj_size (cache_obj_t *obj, size_t *size); +cache_rc_t cache_obj_fetch (cache_obj_t *obj, cache_fetch_t mode, cache_blob_t *val); +cache_rc_t cache_obj_release (cache_obj_t *obj); + +cache_rc_t cache_fetch (cache_t *cache, cache_iter_t *iter, cache_blob_t *val); + +cache_rc_t cache_iter_create (cache_t *cache, cache_iter_t *iter); +cache_rc_t cache_iter_key (cache_t *cache, cache_iter_t *iter); +cache_rc_t cache_iter_destroy(cache_t *cache, cache_iter_t *iter); + +cache_rc_t cache_export (cache_t *cache, void *); +cache_rc_t cache_import (cache_t *cache, void *); + #endif /* __CACHE_H__ */