From: Stephen D. <sd...@us...> - 2005-12-30 11:07:44
|
Update of /cvsroot/naviserver/naviserver/include In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32584/include Modified Files: ns.h Log Message: 2005-12-30 Stephen Deasey <sd...@us...> * include/ns.h: * nsd/nsd.h: * nsd/init.c: * nsd/proc.c: * nsd/cache.c: Global hash of cache names removed; access no longer available via Ns_CacheFind() or ns_cache_names. Caches have unique locking requirements and lifetimes which could be violated by e.g. running ns_cache_stats on a thread local cache as the thread is exiting. New Ns_CacheCreateEx() allows creating a cache which has both a size and a time limit. Caches with time limits are calculated differently. Previous behaviour was to periodically check the last access time of each cache entry and flush those which had expired. A busy cache could grow without bound. New behaviour is to check for expirey each time an entry is retrieved from the cache. All caches can (and should) be size limited. Timeouts may be specified per cache and per entry using new Ns_CacheSetValueExpires(). Ns_CacheFlush() now returns the number of entries flushed. New Ns_CacheStats() takes over from ns_cache_stats for non-Tcl caches. Stats are returned in Tcl "array get" format. Removed Ns_CacheMalloc(), Ns_CacheFree() and Ns_CacheName(). Move Tcl commands to tclcache.c. * nsd/Makefile: * nsd/tclcmds.c: * nsd/tclcache.c: * tests/ns_cache.test: Add new Tcl commands ns_cache_create, _eval, _append, _lappend, and _incr. (RFE# 1119257) Old commands ns_cache_names, _keys, _flush and _stats now only work on Tcl caches. ns_cache_size has been removed; the size is now reported along with other statistics. These commands now only work on Tcl caches. * tcl/cache.tcl: New ns_memoize and related commands which act just like ns_cache_eval but use the script as a key into the memoize cache. Index: ns.h =================================================================== RCS file: /cvsroot/naviserver/naviserver/include/ns.h,v retrieving revision 1.64 retrieving revision 1.65 diff -C2 -d -r1.64 -r1.65 *** ns.h 11 Dec 2005 11:19:50 -0000 1.64 --- ns.h 30 Dec 2005 11:07:33 -0000 1.65 *************** *** 201,205 **** #define NS_TCL_SET_TEMPORARY NS_TCL_SET_STATIC ! #define NS_CACHE_FREE ((Ns_Callback *) (-1)) #ifdef _WIN32 --- 201,205 ---- #define NS_TCL_SET_TEMPORARY NS_TCL_SET_STATIC ! #define NS_CACHE_FREE ns_free #ifdef _WIN32 *************** *** 571,602 **** */ ! NS_EXTERN Ns_Cache *Ns_CacheCreate(char *name, int keys, time_t timeout, ! Ns_Callback *freeProc); ! NS_EXTERN Ns_Cache *Ns_CacheCreateSz(char *name, int keys, size_t maxSize, ! Ns_Callback *freeProc); ! NS_EXTERN void Ns_CacheDestroy(Ns_Cache *cache); ! NS_EXTERN Ns_Cache *Ns_CacheFind(char *name); ! NS_EXTERN void *Ns_CacheMalloc(Ns_Cache *cache, size_t len); ! NS_EXTERN void Ns_CacheFree(Ns_Cache *cache, void *bytes); ! NS_EXTERN Ns_Entry *Ns_CacheFindEntry(Ns_Cache *cache, char *key); ! NS_EXTERN Ns_Entry *Ns_CacheCreateEntry(Ns_Cache *cache, char *key, int *newPtr); ! NS_EXTERN char *Ns_CacheName(Ns_Entry *entry); ! NS_EXTERN char *Ns_CacheKey(Ns_Entry *entry); ! NS_EXTERN void *Ns_CacheGetValue(Ns_Entry *entry); ! NS_EXTERN void Ns_CacheSetValue(Ns_Entry *entry, void *value); ! NS_EXTERN void Ns_CacheSetValueSz(Ns_Entry *entry, void *value, size_t size); ! NS_EXTERN void Ns_CacheUnsetValue(Ns_Entry *entry); ! NS_EXTERN void Ns_CacheDeleteEntry(Ns_Entry *entry); ! NS_EXTERN void Ns_CacheFlushEntry(Ns_Entry *entry); ! NS_EXTERN Ns_Entry *Ns_CacheFirstEntry(Ns_Cache *cache, Ns_CacheSearch *search); ! NS_EXTERN Ns_Entry *Ns_CacheNextEntry(Ns_CacheSearch *search); ! NS_EXTERN void Ns_CacheFlush(Ns_Cache *cache); ! NS_EXTERN void Ns_CacheLock(Ns_Cache *cache); ! NS_EXTERN int Ns_CacheTryLock(Ns_Cache *cache); ! NS_EXTERN void Ns_CacheUnlock(Ns_Cache *cache); ! NS_EXTERN int Ns_CacheTimedWait(Ns_Cache *cache, Ns_Time *timePtr); ! NS_EXTERN void Ns_CacheWait(Ns_Cache *cache); ! NS_EXTERN void Ns_CacheSignal(Ns_Cache *cache); ! NS_EXTERN void Ns_CacheBroadcast(Ns_Cache *cache); /* --- 571,682 ---- */ ! NS_EXTERN Ns_Cache * ! Ns_CacheCreate(CONST char *name, int keys, time_t ttl, Ns_Callback *freeProc) ! NS_GNUC_NONNULL(1); ! ! NS_EXTERN Ns_Cache * ! Ns_CacheCreateSz(CONST char *name, int keys, size_t maxSize, Ns_Callback *freeProc) ! NS_GNUC_NONNULL(1); ! ! NS_EXTERN Ns_Cache * ! Ns_CacheCreateEx(CONST char *name, int keys, time_t ttl, size_t maxSize, ! Ns_Callback *freeProc) ! NS_GNUC_NONNULL(1); ! ! NS_EXTERN void ! Ns_CacheDestroy(Ns_Cache *cache) ! NS_GNUC_NONNULL(1); ! ! NS_EXTERN Ns_Entry * ! Ns_CacheFindEntry(Ns_Cache *cache, CONST char *key) ! NS_GNUC_NONNULL(1) NS_GNUC_NONNULL(2); ! ! NS_EXTERN Ns_Entry * ! Ns_CacheCreateEntry(Ns_Cache *cache, CONST char *key, int *newPtr) ! NS_GNUC_NONNULL(1) NS_GNUC_NONNULL(2) NS_GNUC_NONNULL(3); ! ! NS_EXTERN Ns_Entry * ! Ns_CacheWaitCreateEntry(Ns_Cache *cache, CONST char *key, int *newPtr, time_t timeout) ! NS_GNUC_NONNULL(1) NS_GNUC_NONNULL(2) NS_GNUC_NONNULL(3); ! ! NS_EXTERN char * ! Ns_CacheKey(Ns_Entry *entry) ! NS_GNUC_NONNULL(1); ! ! NS_EXTERN void * ! Ns_CacheGetValue(Ns_Entry *entry) ! NS_GNUC_NONNULL(1); ! ! NS_EXTERN size_t ! Ns_CacheGetSize(Ns_Entry *entry) ! NS_GNUC_NONNULL(1); ! ! NS_EXTERN void ! Ns_CacheSetValue(Ns_Entry *entry, void *value) ! NS_GNUC_NONNULL(1) NS_GNUC_NONNULL(2); ! ! NS_EXTERN void ! Ns_CacheSetValueSz(Ns_Entry *entry, void *value, size_t size) ! NS_GNUC_NONNULL(1) NS_GNUC_NONNULL(2); ! ! NS_EXTERN void ! Ns_CacheSetValueExpires(Ns_Entry *entry, void *value, size_t size, time_t ttl) ! NS_GNUC_NONNULL(1); ! ! NS_EXTERN void ! Ns_CacheUnsetValue(Ns_Entry *entry) ! NS_GNUC_NONNULL(1); ! ! NS_EXTERN void ! Ns_CacheDeleteEntry(Ns_Entry *entry) ! NS_GNUC_NONNULL(1); ! ! NS_EXTERN void ! Ns_CacheFlushEntry(Ns_Entry *entry) ! NS_GNUC_NONNULL(1); ! ! NS_EXTERN Ns_Entry * ! Ns_CacheFirstEntry(Ns_Cache *cache, Ns_CacheSearch *search) ! NS_GNUC_NONNULL(1) NS_GNUC_NONNULL(2); ! ! NS_EXTERN Ns_Entry * ! Ns_CacheNextEntry(Ns_CacheSearch *search) ! NS_GNUC_NONNULL(1); ! ! NS_EXTERN int ! Ns_CacheFlush(Ns_Cache *cache) ! NS_GNUC_NONNULL(1); ! ! NS_EXTERN void ! Ns_CacheLock(Ns_Cache *cache) ! NS_GNUC_NONNULL(1); ! ! NS_EXTERN int ! Ns_CacheTryLock(Ns_Cache *cache) ! NS_GNUC_NONNULL(1); ! ! NS_EXTERN void ! Ns_CacheUnlock(Ns_Cache *cache) ! NS_GNUC_NONNULL(1); ! ! NS_EXTERN void ! Ns_CacheWait(Ns_Cache *cache) ! NS_GNUC_NONNULL(1); ! ! NS_EXTERN int ! Ns_CacheTimedWait(Ns_Cache *cache, Ns_Time *timePtr) ! NS_GNUC_NONNULL(1); ! ! NS_EXTERN void ! Ns_CacheSignal(Ns_Cache *cache) ! NS_GNUC_NONNULL(1); ! ! NS_EXTERN void ! Ns_CacheBroadcast(Ns_Cache *cache) ! NS_GNUC_NONNULL(1); ! ! NS_EXTERN void ! Ns_CacheStats(Ns_Cache *cache, Ns_DString *dest) ! NS_GNUC_NONNULL(1) NS_GNUC_NONNULL(2); /* |