In-memory caching


Typedefs

typedef svn_error_t *(* svn_cache_dup_func_t )(void **out, void *in, apr_pool_t *pool)
 A function type for copying an object in into a different pool pool and returning the result in *out.
typedef svn_error_t *(* svn_cache_deserialize_func_t )(void **out, const char *data, apr_size_t data_len, apr_pool_t *pool)
 A function type for deserializing an object *out from the string data of length data_len in the pool pool.
typedef svn_error_t *(* svn_cache_serialize_func_t )(char **data, apr_size_t *data_len, void *in, apr_pool_t *pool)
 A function type for serializing an object in into bytes.
typedef svn_error_t *(* svn_cache_error_handler_t )(svn_error_t *err, void *baton, apr_pool_t *pool)
 A function type for transforming or ignoring errors.
typedef svn_memcache_t svn_memcache_t
 A wrapper around apr_memcache_t, provided essentially so that the Subversion public API doesn't depend on whether or not you have access to the APR memcache libraries.
typedef svn_cache_t svn_cache_t
 Opaque type for an in-memory cache.

Functions

svn_error_tsvn_cache_create_inprocess (svn_cache_t **cache_p, svn_cache_dup_func_t dup_func, apr_ssize_t klen, apr_int64_t pages, apr_int64_t items_per_page, svn_boolean_t thread_safe, apr_pool_t *pool)
 Creates a new cache in *cache_p.
svn_error_tsvn_cache_create_memcache (svn_cache_t **cache_p, svn_memcache_t *memcache, svn_cache_serialize_func_t serialize_func, svn_cache_deserialize_func_t deserialize_func, apr_ssize_t klen, const char *prefix, apr_pool_t *pool)
 Creates a new cache in *cache_p, communicating to a memcached process via memcache.
svn_error_tsvn_cache_make_memcache_from_config (svn_memcache_t **memcache_p, svn_config_t *config, apr_pool_t *pool)
 Given config, returns an APR memcached interface in *memcache_p allocated in pool if config contains entries in the SVN_CACHE_CONFIG_CATEGORY_MEMCACHED_SERVERS section describing memcached servers; otherwise, sets *memcache_p to NULL.
svn_error_tsvn_cache_set_error_handler (svn_cache_t *cache, svn_cache_error_handler_t handler, void *baton, apr_pool_t *pool)
 Sets handler to be cache's error handling routine.
svn_error_tsvn_cache_get (void **value, svn_boolean_t *found, const svn_cache_t *cache, const void *key, apr_pool_t *pool)
 Fetches a value indexed by key from cache into *value, setting *found to TRUE iff it is in the cache and FALSE if it is not found.
svn_error_tsvn_cache_set (svn_cache_t *cache, const void *key, void *value, apr_pool_t *pool)
 Stores the value value under the key key in cache.
svn_error_tsvn_cache_iter (svn_boolean_t *completed, const svn_cache_t *cache, svn_iter_apr_hash_cb_t func, void *baton, apr_pool_t *pool)
 Iterates over the elements currently in cache, calling func for each one until there are no more elements or func returns an error.

Typedef Documentation

typedef svn_error_t*(* svn_cache_deserialize_func_t)(void **out, const char *data, apr_size_t data_len, apr_pool_t *pool)
 

A function type for deserializing an object *out from the string data of length data_len in the pool pool.

Since:
New in 1.6.

Definition at line 62 of file svn_cache.h.

typedef svn_error_t*(* svn_cache_dup_func_t)(void **out, void *in, apr_pool_t *pool)
 

A function type for copying an object in into a different pool pool and returning the result in *out.

Since:
New in 1.6.

Definition at line 52 of file svn_cache.h.

typedef svn_error_t*(* svn_cache_error_handler_t)(svn_error_t *err, void *baton, apr_pool_t *pool)
 

A function type for transforming or ignoring errors.

pool may be used for temporary allocations.

Since:
New in 1.6.

Definition at line 85 of file svn_cache.h.

typedef svn_error_t*(* svn_cache_serialize_func_t)(char **data, apr_size_t *data_len, void *in, apr_pool_t *pool)
 

A function type for serializing an object in into bytes.

The function should allocate the serialized value in pool, set *data to the serialized value, and set *data_len to its length.

Since:
New in 1.6.

Definition at line 74 of file svn_cache.h.

typedef struct svn_cache_t svn_cache_t
 

Opaque type for an in-memory cache.

Since:
New in 1.6.

Definition at line 103 of file svn_cache.h.

typedef struct svn_memcache_t svn_memcache_t
 

A wrapper around apr_memcache_t, provided essentially so that the Subversion public API doesn't depend on whether or not you have access to the APR memcache libraries.

Since:
New in 1.6.

Definition at line 96 of file svn_cache.h.


Function Documentation

svn_error_t* svn_cache_create_inprocess svn_cache_t **  cache_p,
svn_cache_dup_func_t  dup_func,
apr_ssize_t  klen,
apr_int64_t  pages,
apr_int64_t  items_per_page,
svn_boolean_t  thread_safe,
apr_pool_t *  pool
 

Creates a new cache in *cache_p.

This cache will use pool for all of its storage needs. The elements in the cache will be indexed by keys of length klen, which may be APR_HASH_KEY_STRING if they are strings. Cached values will be copied in and out of the cache using dup_func.

The cache stores up to pages * items_per_page items at a time. The exact cache invalidation strategy is not defined here, but in general, a lower value for items_per_page means more memory overhead for the same number of items, but a higher value for items_per_page means more items are cleared at once. Both pages and items_per_page must be positive (though they both may certainly be 1).

If thread_safe is true, and APR is compiled with threads, all accesses to the cache will be protected with a mutex.

Note that NULL is a legitimate value for cache entries (and dup_func will not be called on it).

It is not safe for dup_func to interact with the cache itself.

Since:
New in 1.6.

svn_error_t* svn_cache_create_memcache svn_cache_t **  cache_p,
svn_memcache_t memcache,
svn_cache_serialize_func_t  serialize_func,
svn_cache_deserialize_func_t  deserialize_func,
apr_ssize_t  klen,
const char *  prefix,
apr_pool_t *  pool
 

Creates a new cache in *cache_p, communicating to a memcached process via memcache.

The elements in the cache will be indexed by keys of length klen, which may be APR_HASH_KEY_STRING if they are strings. Values will be serialized for memcached using serialize_func and deserialized using deserialize_func. Because the same memcached server may cache many different kinds of values, prefix should be specified to differentiate this cache from other caches. *cache_p will be allocated in pool.

If deserialize_func is NULL, then the data is returned as an svn_string_t; if serialize_func is NULL, then the data is assumed to be an svn_stringbuf_t.

These caches are always thread safe.

These caches do not support svn_cache_iter.

If Subversion was not built with apr_memcache support, always raises SVN_ERR_NO_APR_MEMCACHE.

Since:
New in 1.6.

svn_error_t* svn_cache_get void **  value,
svn_boolean_t found,
const svn_cache_t cache,
const void *  key,
apr_pool_t *  pool
 

Fetches a value indexed by key from cache into *value, setting *found to TRUE iff it is in the cache and FALSE if it is not found.

The value is copied into pool using the copy function provided to the cache's constructor.

Since:
New in 1.6.

svn_error_t* svn_cache_iter svn_boolean_t completed,
const svn_cache_t cache,
svn_iter_apr_hash_cb_t  func,
void *  baton,
apr_pool_t *  pool
 

Iterates over the elements currently in cache, calling func for each one until there are no more elements or func returns an error.

Uses pool for temporary allocations.

If completed is not NULL, then on return - if func returns no errors - *completed will be set to TRUE.

If func returns an error other than SVN_ERR_ITER_BREAK, that error is returned. When func returns SVN_ERR_ITER_BREAK, iteration is interrupted, but no error is returned and *completed is set to FALSE. (The error handler set by svn_cache_set_error_handler is not used for svn_cache_iter.)

It is not legal to perform any other cache operations on cache inside func.

svn_cache_iter is not supported by all cache implementations; see the svn_cache_create_* function for details.

Since:
New in 1.6.

svn_error_t* svn_cache_make_memcache_from_config svn_memcache_t **  memcache_p,
svn_config_t config,
apr_pool_t *  pool
 

Given config, returns an APR memcached interface in *memcache_p allocated in pool if config contains entries in the SVN_CACHE_CONFIG_CATEGORY_MEMCACHED_SERVERS section describing memcached servers; otherwise, sets *memcache_p to NULL.

If Subversion was not built with apr_memcache_support, then raises SVN_ERR_NO_APR_MEMCACHE if and only if config is configured to use memcache.

Since:
New in 1.6.

svn_error_t* svn_cache_set svn_cache_t cache,
const void *  key,
void *  value,
apr_pool_t *  pool
 

Stores the value value under the key key in cache.

pool is used only for temporary allocations. The cache makes copies of key and value if necessary (that is, key and value may have shorter lifetimes than the cache).

If there is already a value for key, this will replace it. Bear in mind that in some circumstances this may leak memory (that is, the cache's copy of the previous value may not be immediately cleared); it is only guaranteed to not leak for caches created with items_per_page equal to 1.

Since:
New in 1.6.

svn_error_t* svn_cache_set_error_handler svn_cache_t cache,
svn_cache_error_handler_t  handler,
void *  baton,
apr_pool_t *  pool
 

Sets handler to be cache's error handling routine.

If any error is returned from a call to svn_cache_get or svn_cache_set, handler will be called with baton and the error, and the original function will return whatever error handler returns instead (possibly SVN_NO_ERROR); handler will receive the pool passed to the svn_cache_* function. pool is used for temporary allocations.

Since:
New in 1.6.


Generated on Tue Oct 7 04:09:58 2008 for Subversion by  doxygen 1.3.9.1