Cache API

Functions that affect only the cache. More...

Functions

ssize_t nmdb_cache_get (nmdb_t *db, const unsigned char *key, size_t ksize, unsigned char *val, size_t vsize)
 Get the value associated with a key from cache.
int nmdb_cache_set (nmdb_t *db, const unsigned char *key, size_t ksize, const unsigned char *val, size_t vsize)
 Set the value associated with a key, but only in the cache.
int nmdb_cache_del (nmdb_t *db, const unsigned char *key, size_t ksize)
 Delete a key, but only from the cache.
int nmdb_cache_cas (nmdb_t *db, const unsigned char *key, size_t ksize, const unsigned char *oldval, size_t ovsize, const unsigned char *newval, size_t nvsize)
 Perform an atomic compare-and-swap only on the cache.
int nmdb_cache_incr (nmdb_t *db, const unsigned char *key, size_t ksize, int64_t increment, int64_t *newval)
 Atomically increment the value associated with a key only in the cache.

Detailed Description

Functions that affect only the cache.


Function Documentation

ssize_t nmdb_cache_get ( nmdb_t db,
const unsigned char *  key,
size_t  ksize,
unsigned char *  val,
size_t  vsize 
)

Get the value associated with a key from cache.

This is just like nmdb_get(), except it only queries the caches, and never the database.

Parameters:
db connection instance.
key the key.
ksize the key size.
[out] val buffer where the value will be stored.
vsize size of the value buffer.
Returns:
the size of the value written to the given buffer, -1 if the key is not in the cache, or -2 if there was an error.
int nmdb_cache_set ( nmdb_t db,
const unsigned char *  key,
size_t  ksize,
const unsigned char *  val,
size_t  vsize 
)

Set the value associated with a key, but only in the cache.

This command sets the key's value in the cache, but does NOT affect the backend database. Combining it with nmdb_set() and/or nmdb_set_sync() is not recommended, because consistency issues may arise.

Parameters:
db connection instance.
key the key.
ksize the key size.
val the value
vsize size of the value.
Returns:
1 on success, < 0 on error.
int nmdb_cache_del ( nmdb_t db,
const unsigned char *  key,
size_t  ksize 
)

Delete a key, but only from the cache.

This command deletes a key from the cache, but does NOT affect the backend database. Combining it with nmdb_del() and/or nmdb_del_sync() is not recommended, because consistency issues may arise.

Parameters:
db connection instance.
key the key.
ksize the key size.
Returns:
1 on success, < 0 on error.
int nmdb_cache_cas ( nmdb_t db,
const unsigned char *  key,
size_t  ksize,
const unsigned char *  oldval,
size_t  ovsize,
const unsigned char *  newval,
size_t  nvsize 
)

Perform an atomic compare-and-swap only on the cache.

This command works just like nmdb_cas(), except it affects only the cache, and not the backend database. Equivalent to atomically doing:

if get_cache(key) == oldval, then set_cache(key, newval)

Parameters:
db connection instance.
key the key.
ksize the key size.
oldval the old, expected value.
ovsize size of the expected value.
newval the new value to set.
nvsize size of the new value.
Returns:
2 on success, 1 if the current value does not match oldval, 0 if the key is not in the database, or < 0 on error.
int nmdb_cache_incr ( nmdb_t db,
const unsigned char *  key,
size_t  ksize,
int64_t  increment,
int64_t *  newval 
)

Atomically increment the value associated with a key only in the cache.

This command works just like nmdb_incr(), except it affects only the cache, and not the backend database.

Parameters:
db connection instance.
key the key.
ksize the key size.
increment the value to add to the current one (can be negative).
[out] newval pointer to an integer that will be set to the new value.
Returns:
2 if the increment was successful, 1 if the current value was not in an appropriate format, 0 if the key is not in the database, or < 0 on error.
Generated on Sun Oct 10 19:50:36 2010 for libnmdb (public) by  doxygen 1.6.3