memcached  1.6.15
About: memcached is a high-performance, distributed memory object caching system, generic in nature, but originally intended for use in speeding up dynamic web applications by alleviating database load.
  Fossies Dox: memcached-1.6.15.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

cache.h File Reference
#include <pthread.h>
#include "queue.h"
Include dependency graph for cache.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  cache_free_s
 
struct  cache_t
 
struct  cache_t::cache_head
 

Functions

cache_tcache_create (const char *name, size_t bufsize, size_t align)
 
void cache_destroy (cache_t *handle)
 
voidcache_alloc (cache_t *handle)
 
voiddo_cache_alloc (cache_t *handle)
 
void cache_free (cache_t *handle, void *ptr)
 
void do_cache_free (cache_t *handle, void *ptr)
 
void cache_set_limit (cache_t *handle, int limit)
 

Variables

int cache_error
 

Function Documentation

◆ cache_alloc()

void * cache_alloc ( cache_t handle)

Allocate an object from the cache.

Parameters
handlethe handle to the object cache to allocate from
Returns
a pointer to an initialized object from the cache, or NULL if the allocation cannot be satisfied.

Definition at line 67 of file cache.c.

References do_cache_alloc(), and cache_t::mutex.

Referenced by cache_bulkalloc(), cache_limit_revised_downward_test(), cache_redzone_test(), cache_reuse_test(), and cqi_new().

◆ cache_create()

cache_t * cache_create ( const char *  name,
size_t  bufsize,
size_t  align 
)

Create an object cache.

The object cache will let you allocate objects of the same size. It is fully MT safe, so you may allocate objects from multiple threads without having to do any synchronization in the application code.

Parameters
namethe name of the object cache. This name may be used for debug purposes and may help you track down what kind of object you have problems with (buffer overruns, leakage etc)
bufsizethe size of each object in the cache
alignthe alignment requirements of the objects in the cache.
constructorthe function to be called to initialize memory when we need to allocate more memory from the os.
destructorthe function to be called before we release the memory back to the os.
Returns
a handle to an object cache if successful, NULL otherwise.

Definition at line 18 of file cache.c.

References cache_t::bufsize, cache_t::head, cache_t::mutex, cache_t::name, redzone_pattern, and STAILQ_INIT.

Referenced by cache_bulkalloc(), cache_create_test(), cache_limit_revised_downward_test(), cache_redzone_test(), cache_reuse_test(), cq_init(), and setup_thread().

◆ cache_destroy()

void cache_destroy ( cache_t handle)

Destroy an object cache.

Destroy and invalidate an object cache. You should return all buffers allocated with cache_alloc by using cache_free before calling this function. Not doing so results in undefined behavior (the buffers may or may not be invalidated)

Parameters
handlethe handle to the object cache to destroy.

Definition at line 56 of file cache.c.

References cache_free_s::c_next, cache_t::head, cache_t::mutex, cache_t::name, STAILQ_EMPTY, STAILQ_FIRST, and STAILQ_REMOVE_HEAD.

Referenced by cache_bulkalloc(), cache_create_test(), cache_limit_revised_downward_test(), cache_redzone_test(), and cache_reuse_test().

◆ cache_free()

void cache_free ( cache_t handle,
void ptr 
)

Return an object back to the cache.

The caller should return the object in an initialized state so that the object may be returned in an expected state from cache_alloc.

Parameters
handlehandle to the object cache to return the object to
ptrpointer to the object to return.

Definition at line 108 of file cache.c.

References do_cache_free(), and cache_t::mutex.

Referenced by cache_bulkalloc(), cache_limit_revised_downward_test(), cache_redzone_test(), cache_reuse_test(), and cqi_free().

◆ cache_set_limit()

void cache_set_limit ( cache_t handle,
int  limit 
)

Set or adjust a limit for the number of objects to malloc

Parameters
handlehandle to the object cache to adjust
limitthe number of objects to cache before returning NULL

Definition at line 41 of file cache.c.

References cache_t::limit, and cache_t::mutex.

Referenced by cache_limit_revised_downward_test(), and setup_thread().

◆ do_cache_alloc()

◆ do_cache_free()

Variable Documentation

◆ cache_error

int cache_error
extern

Definition at line 15 of file cache.c.

Referenced by cache_redzone_test(), and do_cache_free().