#include "nsd.h"Data Structures | |
| struct | Entry |
| struct | Cache |
Functions | |
| void | NsInitCache (void) |
| Ns_Cache * | Ns_CacheCreate (char *name, int keys, time_t timeout, Ns_Callback *freeProc) |
| Ns_Cache * | Ns_CacheCreateSz (char *name, int keys, size_t maxSize, Ns_Callback *freeProc) |
| void | Ns_CacheDestroy (Ns_Cache *cache) |
| Ns_Cache * | Ns_CacheFind (char *name) |
| void * | Ns_CacheMalloc (Ns_Cache *cache, size_t len) |
| void | Ns_CacheFree (Ns_Cache *cache, void *ptr) |
| Ns_Entry * | Ns_CacheFindEntry (Ns_Cache *cache, char *key) |
| Ns_Entry * | Ns_CacheCreateEntry (Ns_Cache *cache, char *key, int *newPtr) |
| char * | Ns_CacheName (Ns_Entry *entry) |
| char * | Ns_CacheKey (Ns_Entry *entry) |
| void * | Ns_CacheGetValue (Ns_Entry *entry) |
| void | Ns_CacheSetValue (Ns_Entry *entry, void *value) |
| void | Ns_CacheSetValueSz (Ns_Entry *entry, void *value, size_t size) |
| void | Ns_CacheUnsetValue (Ns_Entry *entry) |
| void | Ns_CacheDeleteEntry (Ns_Entry *entry) |
| void | Ns_CacheFlushEntry (Ns_Entry *entry) |
| Ns_Entry * | Ns_CacheFirstEntry (Ns_Cache *cache, Ns_CacheSearch *search) |
| Ns_Entry * | Ns_CacheNextEntry (Ns_CacheSearch *search) |
| void | Ns_CacheFlush (Ns_Cache *cache) |
| void | Ns_CacheLock (Ns_Cache *cache) |
| int | Ns_CacheTryLock (Ns_Cache *cache) |
| void | Ns_CacheUnlock (Ns_Cache *cache) |
| int | Ns_CacheTimedWait (Ns_Cache *cache, Ns_Time *timePtr) |
| void | Ns_CacheWait (Ns_Cache *cache) |
| void | Ns_CacheSignal (Ns_Cache *cache) |
| void | Ns_CacheBroadcast (Ns_Cache *cache) |
| void | NsCacheArgProc (Tcl_DString *dsPtr, void *arg) |
| int | NsTclCacheNamesCmd (ClientData dummy, Tcl_Interp *interp, int argc, char **argv) |
| int | NsTclCacheStatsCmd (ClientData dummy, Tcl_Interp *interp, int argc, char **argv) |
| int | NsTclCacheFlushCmd (ClientData dummy, Tcl_Interp *interp, int argc, char **argv) |
| int | NsTclCacheSizeCmd (ClientData dummy, Tcl_Interp *interp, int argc, char **argv) |
| int | NsTclCacheKeysCmd (ClientData dummy, Tcl_Interp *interp, int argc, char **argv) |
| void | NsCachePurge (void *arg) |
| void Ns_CacheBroadcast | ( | Ns_Cache * | cache | ) |
----------------------------------------------------------------------
Ns_CacheBroadcast --
Broadcast the cache's condition variable, waking all waiting threads (if any).
Results: None.
Side effects: Threads may resume.
----------------------------------------------------------------------
| Ns_Cache* Ns_CacheCreate | ( | char * | name, | |
| int | keys, | |||
| time_t | timeout, | |||
| Ns_Callback * | freeProc | |||
| ) |
----------------------------------------------------------------------
Ns_CacheCreate --
Calls CacheCreate with an unlimited max size.
Results: See CacheCreate()
Side effects: See CacheCreate()
----------------------------------------------------------------------
| Ns_Entry* Ns_CacheCreateEntry | ( | Ns_Cache * | cache, | |
| char * | key, | |||
| int * | newPtr | |||
| ) |
----------------------------------------------------------------------
Ns_CacheCreateEntry --
Create a new cache entry; this function emulates Tcl_CreateHashEntry's interface
Results: A pointer to a new cache entry
Side effects: Memory will be allocated for the new cache entry and it will be inserted into the cache.
----------------------------------------------------------------------
| Ns_Cache* Ns_CacheCreateSz | ( | char * | name, | |
| int | keys, | |||
| size_t | maxSize, | |||
| Ns_Callback * | freeProc | |||
| ) |
----------------------------------------------------------------------
Ns_CacheCreateSz --
See CacheCreate()
Results: See CacheCreate()
Side effects: See CacheCreate()
----------------------------------------------------------------------
| void Ns_CacheDeleteEntry | ( | Ns_Entry * | entry | ) |
----------------------------------------------------------------------
Ns_CacheDeleteEntry --
Delete an entry from the cache table.
Results: None.
Side effects: None.
----------------------------------------------------------------------
| void Ns_CacheDestroy | ( | Ns_Cache * | cache | ) |
----------------------------------------------------------------------
Ns_CacheDestroy
Flush all entries and delete a cache.
Results: None.
Side effects: Cache no longer usable.
----------------------------------------------------------------------
Unschedule the flusher if time-based cache.
Wait for currently running flusher to exit.
Flush all entries.
Remove from cache table and free cache structure.
| Ns_Cache* Ns_CacheFind | ( | char * | name | ) |
----------------------------------------------------------------------
Ns_CacheFind --
Find a cache by name.
Results: A pointer to an Ns_Cache or NULL
Side effects: None.
----------------------------------------------------------------------
| Ns_Entry* Ns_CacheFindEntry | ( | Ns_Cache * | cache, | |
| char * | key | |||
| ) |
----------------------------------------------------------------------
Ns_CacheFindEntry --
Find a cache entry
Results: A pointer to an Ns_Entry cache entry
Side effects: The cache entry will move to the top of the LRU list.
----------------------------------------------------------------------
| Ns_Entry* Ns_CacheFirstEntry | ( | Ns_Cache * | cache, | |
| Ns_CacheSearch * | search | |||
| ) |
----------------------------------------------------------------------
Ns_CacheFirstEntry --
Return a pointer to the first entry in the cache (in no particular order)
Results: A pointer to said entry.
Side effects: None.
----------------------------------------------------------------------
| void Ns_CacheFlush | ( | Ns_Cache * | cache | ) |
----------------------------------------------------------------------
Ns_CacheFlush --
Flush every entry from a cache.
Results: None.
Side effects: None.
----------------------------------------------------------------------
| void Ns_CacheFlushEntry | ( | Ns_Entry * | entry | ) |
----------------------------------------------------------------------
Ns_CacheFlushEntry --
Delete an entry from the cache table after first unsetting the current entry value (if any).
Results: None.
Side effects: None.
----------------------------------------------------------------------
| void Ns_CacheFree | ( | Ns_Cache * | cache, | |
| void * | ptr | |||
| ) |
----------------------------------------------------------------------
Ns_CacheFree --
Frees memory allocated from Ns_CacheMalloc
Results: None.
Side effects: None.
----------------------------------------------------------------------
| void* Ns_CacheGetValue | ( | Ns_Entry * | entry | ) |
----------------------------------------------------------------------
Ns_CacheGetValue --
Get the value (contents) of a cache entry
Results: A pointer to the cache entry's contents
Side effects: None.
----------------------------------------------------------------------
| char* Ns_CacheKey | ( | Ns_Entry * | entry | ) |
----------------------------------------------------------------------
Ns_CacheKey --
Gets the key of a cache entry
Results: A pointer to the key for the given entry
Side effects: None.
----------------------------------------------------------------------
| void Ns_CacheLock | ( | Ns_Cache * | cache | ) |
| void* Ns_CacheMalloc | ( | Ns_Cache * | cache, | |
| size_t | len | |||
| ) |
----------------------------------------------------------------------
Ns_CacheMalloc --
Allocate memory from a cache-local pool.
Results: A pointer to new memory.
Side effects: None.
----------------------------------------------------------------------
| char* Ns_CacheName | ( | Ns_Entry * | entry | ) |
----------------------------------------------------------------------
Ns_CacheName --
Gets the name of the cache
Results: A pointer to a null-terminated string
Side effects: None.
----------------------------------------------------------------------
| Ns_Entry* Ns_CacheNextEntry | ( | Ns_CacheSearch * | search | ) |
----------------------------------------------------------------------
Ns_CacheNextEntry --
When used in conjunction with Ns_CacheFirstEntry, one may walk through the whole cache.
Results: NULL or a pointer to an entry
Side effects: None.
----------------------------------------------------------------------
| void Ns_CacheSetValue | ( | Ns_Entry * | entry, | |
| void * | value | |||
| ) |
----------------------------------------------------------------------
Ns_CacheSetValue --
Set the value of a cache entry
Results: None.
Side effects: See Ns_CacheSetValueSz
----------------------------------------------------------------------
| void Ns_CacheSetValueSz | ( | Ns_Entry * | entry, | |
| void * | value, | |||
| size_t | size | |||
| ) |
----------------------------------------------------------------------
Ns_CacheSetValueSz --
Free the cache entry's previous contents, set it to the new contents, increase the size of the cache, and prune until it's back under the maximum size.
Results: None.
Side effects: Cache pruning and freeing of old contents may occur.
----------------------------------------------------------------------
| void Ns_CacheSignal | ( | Ns_Cache * | cache | ) |
----------------------------------------------------------------------
Ns_CacheSignal --
Signal the cache's condition variable, waking the first waiting thread (if any).
NOTE: Be sure you don't really want to wake all threads with Ns_CacheBroadcast.
Results: None.
Side effects: A single thread may resume.
----------------------------------------------------------------------
| int Ns_CacheTimedWait | ( | Ns_Cache * | cache, | |
| Ns_Time * | timePtr | |||
| ) |
----------------------------------------------------------------------
Ns_CacheTimedWait --
Wait for the cache's condition variable to be signaled or the given absolute timeout if timePtr is not NULL.
Results: None.
Side effects: Thread is suspended until condition is signaled or timeout.
----------------------------------------------------------------------
| int Ns_CacheTryLock | ( | Ns_Cache * | cache | ) |
----------------------------------------------------------------------
Ns_CacheTryLock --
Try to lock the cache.
Results: NS_OK if cache is locked, NS_TIMEOUT if not.
Side effects: Mutex may eventually be locked.
----------------------------------------------------------------------
| void Ns_CacheUnlock | ( | Ns_Cache * | cache | ) |
----------------------------------------------------------------------
Ns_CacheUnlock --
Unlock the cache entry
Results: None.
Side effects: Mutex unlocked.
----------------------------------------------------------------------
| void Ns_CacheUnsetValue | ( | Ns_Entry * | entry | ) |
----------------------------------------------------------------------
Ns_CacheUnsetValue --
Reset the value of an entry to NULL, calling the free proc for any previous entry an updating the cache size.
Results: None.
Side effects: None.
----------------------------------------------------------------------
| void Ns_CacheWait | ( | Ns_Cache * | cache | ) |
----------------------------------------------------------------------
Ns_CacheWait --
Wait indefinitely for the cache's condition variable to be signaled.
Results: None.
Side effects: Thread is suspended until condition is signaled.
----------------------------------------------------------------------
| void NsCacheArgProc | ( | Tcl_DString * | dsPtr, | |
| void * | arg | |||
| ) |
----------------------------------------------------------------------
NsCacheArgProc --
Info proc for timed cache schedule procedure callback.
Results: None.
Side effects: Adds name of cache to given dstring.
----------------------------------------------------------------------
| void NsCachePurge | ( | void * | arg | ) |
----------------------------------------------------------------------
NsCachePurge --
Call free procs for all entries that have expired and delete them.
Results: None.
Side effects: Expired entries will be removed.
----------------------------------------------------------------------
| void NsInitCache | ( | void | ) |
----------------------------------------------------------------------
NsInitCache --
Initialize the cache API.
Results: None.
Side effects: None.
----------------------------------------------------------------------
| int NsTclCacheFlushCmd | ( | ClientData | dummy, | |
| Tcl_Interp * | interp, | |||
| int | argc, | |||
| char ** | argv | |||
| ) |
----------------------------------------------------------------------
NsTclCacheFlushCmd --
Wipe out a cache entry
Results: TCL result.
Side effects: A cache will be cleared.
----------------------------------------------------------------------
| int NsTclCacheKeysCmd | ( | ClientData | dummy, | |
| Tcl_Interp * | interp, | |||
| int | argc, | |||
| char ** | argv | |||
| ) |
----------------------------------------------------------------------
NsTclCacheKeysCmd --
Get cache keys.
Results: TCL result.
Side effects: None.
----------------------------------------------------------------------
| int NsTclCacheNamesCmd | ( | ClientData | dummy, | |
| Tcl_Interp * | interp, | |||
| int | argc, | |||
| char ** | argv | |||
| ) |
----------------------------------------------------------------------
NsTclNamesCmd --
Spit back a list of cache names
Results: Tcl result.
Side effects: A list of cache names will be appended to the interp result.
----------------------------------------------------------------------
| int NsTclCacheSizeCmd | ( | ClientData | dummy, | |
| Tcl_Interp * | interp, | |||
| int | argc, | |||
| char ** | argv | |||
| ) |
----------------------------------------------------------------------
NsTclCacheSizeCmd --
Returns current size of a cache.
Results: Tcl result.
Side effects: Results will be appended to interp.
----------------------------------------------------------------------
| int NsTclCacheStatsCmd | ( | ClientData | dummy, | |
| Tcl_Interp * | interp, | |||
| int | argc, | |||
| char ** | argv | |||
| ) |
----------------------------------------------------------------------
NsTclCacheStatsCmds --
Returns stats on a cache
Results: Tcl result.
Side effects: Results will be appended to interp.
----------------------------------------------------------------------
1.5.1