2 * Simple and Quick Shared Memory Cache
4 * (c) 2005 Martin Mares <mj@ucw.cz>
12 uns block_size; /* Cache block size (a power of two) */
13 uns cache_size; /* Size of the whole cache */
14 uns max_entries; /* Maximum number of cached entries */
15 int force_reset; /* Force creation of a new cache even if the old one seems usable, -1 if reset should never be done */
16 uns format_id; /* Data format ID (old cache not used if formats differ) */
19 typedef byte qache_key_t[16];
23 /* Create and destroy a cache */
24 struct qache *qache_open(struct qache_params *p);
25 void qache_close(struct qache *q, uns retain_data);
27 /* Insert new item to the cache with a given key and data. If pos_hint is non-zero, it serves
28 * as a hint about the position of the entry (if it's known that an entry with the particular key
29 * was located there a moment ago. Returns position of the new entry.
31 uns qache_insert(struct qache *q, qache_key_t *key, uns pos_hint, void *data, uns size);
33 /* Look up data in the cache, given a key and a position hint (as above). If datap is non-NULL, data
34 * from the cache entry are copied either to *datap (if *datap is NULL, new memory is allocated by
35 * calling xmalloc and *datap is set to point to that memory). The *sizep contains the maximum number
36 * of bytes to be copied (~0U if unlimited) and it is replaced by the number of bytes available (so it
37 * can be greater than the original value requested). The start indicates starting offset inside the
40 uns qache_lookup(struct qache *q, qache_key_t *key, uns pos_hint, void **datap, uns *sizep, uns start);
42 /* Delete data from the cache, given a key and a position hint. */
43 uns qache_delete(struct qache *q, qache_key_t *key, uns pos_hint);
45 /* Debugging dump (beware, doesn't lock the cache!) */
46 void qache_debug(struct qache *q);