AxlCache — TTL Cache
See AxlData — Data Structures for an overview of all data modules including the TTL cache.
Header: <axl/axl-cache.h>
API Reference
Typedefs
Functions
-
AxlCache *axl_cache_new(size_t max_slots, size_t entry_size, uint64_t ttl_ms)
Create a new TTL cache.
- Parameters:
max_slots – maximum number of cached entries
entry_size – size of each value in bytes
ttl_ms – time-to-live per entry in milliseconds
- Returns:
new cache, or NULL on allocation failure. Free with axl_cache_free().
-
int axl_cache_put(AxlCache *c, const char *key, const void *value)
Store a value in the cache.
Copies
valueinto the cache underkey. Ifkeyalready exists, the entry is refreshed. If the cache is full, the oldest (LRU) entry is evicted.- Parameters:
c – cache
key – string key (copied internally)
value – value to store (entry_size bytes copied)
- Returns:
AXL_OK on success, AXL_ERR on error.
-
int axl_cache_get(AxlCache *c, const char *key, void *value)
Look up a value by key.
Copies the cached value into
valueif found and not expired. Expired entries are treated as misses and invalidated.- Parameters:
c – cache
key – string key
value – [out] receives entry_size bytes
- Returns:
AXL_OK on hit, AXL_ERR on miss or error.