Classes | Macros | Typedefs | Functions
Cache and Backing Store Group

The Cache and Backing Store Group contain the API for configuring caches and backing stores. More...

Classes

struct  mdbm_bsops
 

Macros

#define MDBM_CACHEMODE_NONE   0
 No caching behavior. More...
 
#define MDBM_CACHEMODE_LFU   1
 Entry with smallest number of accesses is evicted. More...
 
#define MDBM_CACHEMODE_LRU   2
 Entry with oldest access time is evicted. More...
 
#define MDBM_CACHEMODE_GDSF   3
 Greedy dual-size frequency (size and frequency) eviction. More...
 
#define MDBM_CACHEMODE_MAX   3
 Maximum cache mode value. More...
 
#define MDBM_CACHEMODE_EVICT_CLEAN_FIRST   0x10
 add to cachemode to evict clean items 1st More...
 
#define MDBM_CACHEMODE(m)   ((m)&3)
 Extracts cache mode. More...
 
#define MDBM_CACHEMODE_BITS   (3 | MDBM_CACHEMODE_EVICT_CLEAN_FIRST)
 Defines a mask for the cache mode, including control (eviction) bit. More...
 
#define MDBM_BSOPS_FILE   ((const mdbm_bsops_t*)-1)
 Backing store File identifier. More...
 
#define MDBM_BSOPS_MDBM   ((const mdbm_bsops_t*)-2)
 Backing store MDBM identifier. More...
 

Typedefs

typedef struct mdbm_bsops mdbm_bsops_t
 

Functions

int mdbm_set_cachemode (MDBM *db, int cachemode)
 Manage the database as a cache. More...
 
int mdbm_get_cachemode (MDBM *db)
 Returns the current cache style of the database. More...
 
const char * mdbm_get_cachemode_name (int cachemode)
 Returns the cache mode as a string. More...
 
int mdbm_set_backingstore (MDBM *cachedb, const mdbm_bsops_t *bsops, void *opt, int flags)
 The backing-store support controls the in-memory cache as a read-through, write-through cache. More...
 

Detailed Description

The Cache and Backing Store Group contain the API for configuring caches and backing stores.

Macro Definition Documentation

#define MDBM_CACHEMODE_NONE   0

No caching behavior.

#define MDBM_CACHEMODE_LFU   1

Entry with smallest number of accesses is evicted.

#define MDBM_CACHEMODE_LRU   2

Entry with oldest access time is evicted.

#define MDBM_CACHEMODE_GDSF   3

Greedy dual-size frequency (size and frequency) eviction.

#define MDBM_CACHEMODE_MAX   3

Maximum cache mode value.

#define MDBM_CACHEMODE_EVICT_CLEAN_FIRST   0x10

add to cachemode to evict clean items 1st

#define MDBM_CACHEMODE (   m)    ((m)&3)

Extracts cache mode.

#define MDBM_CACHEMODE_BITS   (3 | MDBM_CACHEMODE_EVICT_CLEAN_FIRST)

Defines a mask for the cache mode, including control (eviction) bit.

#define MDBM_BSOPS_FILE   ((const mdbm_bsops_t*)-1)

Backing store File identifier.

#define MDBM_BSOPS_MDBM   ((const mdbm_bsops_t*)-2)

Backing store MDBM identifier.

Typedef Documentation

typedef struct mdbm_bsops mdbm_bsops_t

Function Documentation

int mdbm_set_cachemode ( MDBM db,
int  cachemode 
)

Manage the database as a cache.

mdbm_set_cachemode must be called before data is inserted. Tracking metadata is stored with each entry which allows MDBM to do cache eviction via LRU, LFU, and GDSF (greedy-dual-size-frequency). MDBM also supports clean/dirty tracking and the application can supply a callback (see mdbm_set_backingstore) which is called by MDBM when a dirty entry is about to be evicted allowing the application to sync the entry to a backing store or perform some other type of "clean" operation.

NOTE: V3 API

Parameters
[in,out]dbDatabase handle
[in]cachemodecaching mode value (below)
Returns
Set cache mode status
Return values
-1Error, with errno set.
  • ENOSYS: wrong MDBM version
  • EINVAL: bad cachemode value, or empty MDBM
  • other: for locking errors
0Success

Values for cachemode:

  • MDBM_CACHEMODE_NONE - no cache mode
  • MDBM_CACHEMODE_LFU - least frequently used
  • MDBM_CACHEMODE_LRU - least recently used
  • MDBM_CACHEMODE_GDSF - greedy dual-size frequency
int mdbm_get_cachemode ( MDBM db)

Returns the current cache style of the database.

See the cachemode parameter in mdbm_set_cachemode for the valid values.

NOTE: V3 API

Parameters
[in,out]dbDatabase handle
Returns
Current cache mode
Return values
-1error, with errno set.
  • ENOSYS: wrong MDBM version
MDBM_CACHEMODE_NONE
MDBM_CACHEMODE_LFU
MDBM_CACHEMODE_LRU
MDBM_CACHEMODE_GDSF
const char* mdbm_get_cachemode_name ( int  cachemode)

Returns the cache mode as a string.

See mdbm_set_cachemode

NOTE: V3 API

Parameters
[in,out]cachemodeCache mode type (below)
Returns
Printable string representing a valid cache mode, otherwise the string "unknown"

Values for cachemode:

  • MDBM_CACHEMODE_NONE - no cache mode
  • MDBM_CACHEMODE_LFU - least frequently used
  • MDBM_CACHEMODE_LRU - least recently used
  • MDBM_CACHEMODE_GDSF - greedy dual-size frequency
int mdbm_set_backingstore ( MDBM cachedb,
const mdbm_bsops_t bsops,
void *  opt,
int  flags 
)

The backing-store support controls the in-memory cache as a read-through, write-through cache.

The backing-store interface uses a plugin model where each plugin supplies lock, unlock, fetch, store, and delete functions. Two predefined plugins are available: file-based(MDBM_BSOPS_FILE) and MDBM-based (MDBM_BSOPS_MDBM). Typically, a window will be set to access the backing store via mdbm_set_window_size since the backing store may be very large. Please refer to mdbm_set_window_size for window size restrictions.

An mdbm_store on cachedb must be used to update data in the backing store. An in-place update (fetching the data address using mdbm_fetch and directly modifying the data within the mapped db) will not get written through to the backing store.

Once backing store is set on the opened cache, it cannot be removed from the open cache.

If you use MDBM_BSOPS_MDBM to set an MDBM backing store, the cachedb will own the MDBM handle of the backing store, and cachedb will close it when the cache MDBM handle is closed. You should not make any MDBM calls directly using the backing store MDBM handle after passing it to mdbm_set_backingstore.

NOTE: V3 API

Parameters
[in,out]cachedbDatabase handle (for the cache database)
[in]bsopsCan be MDBM_BSOPS_FILE, MDBM_BSOPS_MDBM, or user-supplied functions
[in]optDepends on the bsops parameter. (ex., for MDBM_BSOPS_FILE opt should be a file path, or for MDBM_BSOPS_MDBM opt should be an MDBM database handle (opened with MDBM_OPEN_WINDOWED flag))
[in]flagsDepends on the bsops. Specify 0 if bsops is MDBM_BSOPS_MDBM. Specify O_DIRECT to prevent paging out important data when the bsops is MDBM_BSOPS_FILE.
Returns
Set backingstore status
Return values
-1Error
0Success