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 int force_reset; /* Force creation of a new cache even if the old one seems usable, -1 if reset should never be done */
15 uns format_id; /* Data format ID (old cache not used if formats differ) */
18 typedef byte qache_key_t[16];
20 /* Create and destroy a cache */
21 struct qache *qache_init(struct qache_params *p);
22 void qache_cleanup(struct qache *q, uns retain_data);
24 /* Insert new item to the cache with a given key and data. If pos_hint is non-zero, it serves
25 * as a hint about the position of the entry (if it's known that an entry with the particular key
26 * was located there a moment ago. Returns position of the new entry.
28 uns qache_insert(struct qache *q, qache_key_t *key, uns pos_hint, void *data, uns size);
30 /* Look up data in the cache, given a key and a position hint (as above). If datap is non-NULL, data
31 * from the cache entry are copied either to *datap (if *datap is NULL, new memory is allocated by
32 * calling xmalloc and *datap is set to point to that memory). The *sizep contains the maximum number
33 * of bytes to be copied (~0U if unlimited) and it is replaced by the number of bytes available (so it
34 * can be greater than the original value requested). The start indicates starting offset inside the
37 uns qache_lookup(struct qache *q, qache_key_t *key, uns pos_hint, void **datap, uns **sizep, uns start);
39 /* Delete data from the cache, given a key and a position hint. */
40 uns qache_delete(struct qache *q, qache_key_t *key, uns pos_hint);