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

typedef struct AxlCache AxlCache

axl-cache.h:

TTL cache with LRU eviction. Fixed-size slots, string keys, opaque fixed-size values. Thread-safe: no (single-threaded UEFI).

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 value into the cache under key. If key already 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 value if 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.

void axl_cache_invalidate(AxlCache *c, const char *key)

Invalidate a specific key. No-op if not found.

Parameters:
  • c – cache

  • key – key to remove

void axl_cache_free(AxlCache *c)

Free a cache and all its entries. NULL-safe.

Parameters:
  • c – cache to free