5 /* Generic cache layer. See cache.c for more information. */
7 #include <sys/types.h> /* for size_t */
8 #include <stdint.h> /* for int64_t */
14 /* set directly by initialization */
21 /* the cache data itself */
22 struct cache_chain
*table
;
31 struct cache_entry
*prev
;
32 struct cache_entry
*next
;
38 /* the entries live inside the chain, to avoid allocation costs and
39 * make it more cache-friendly */
40 struct cache_entry entries
[CHAINLEN
];
42 /* these point to elements of the entries array */
43 struct cache_entry
*first
;
44 struct cache_entry
*last
;
48 struct cache
*cache_create(size_t numobjs
, unsigned int flags
);
49 int cache_free(struct cache
*cd
);
50 int cache_get(struct cache
*cd
, const unsigned char *key
, size_t ksize
,
51 unsigned char **val
, size_t *vsize
);
52 int cache_set(struct cache
*cd
, const unsigned char *k
, size_t ksize
,
53 const unsigned char *v
, size_t vsize
);
54 int cache_del(struct cache
*cd
, const unsigned char *key
, size_t ksize
);
55 int cache_cas(struct cache
*cd
, const unsigned char *key
, size_t ksize
,
56 const unsigned char *oldval
, size_t ovsize
,
57 const unsigned char *newval
, size_t nvsize
);
58 int cache_incr(struct cache
*cd
, const unsigned char *key
, size_t ksize
,
59 int64_t increment
, int64_t *newval
);