Smart caching layer for Hindsight operations.
Features:
- TTL-based expiry
- LRU eviction when max entries exceeded
- Stale-while-revalidate for fast responses
- Background refresh before TTL expiry
- Manual invalidation
Cache Keys
- Recall:
{:recall, query_hash, opts_hash} - Reflect:
{:reflect, question_hash}
Summary
Functions
Returns a specification to start this module under a supervisor.
Clears all cached entries.
Gets a cached value by key, returning {:hit, value} or :miss.
Gets a cached value, allowing stale data within grace period.
Returns {:hit, value} or {:stale, value} or :miss.
Invalidates a specific cache entry.
Invalidates entries matching a key prefix/pattern.
Stores a value in the cache with TTL.
Generates a cache key for recall operations.
Generates a cache key for reflect operations.
Starts the cache GenServer.
Returns cache statistics.
Types
@type cache_entry() :: %{ value: term(), inserted_at: integer(), ttl_ms: pos_integer(), last_access: integer() }
@type stats() :: %{ hits: non_neg_integer(), misses: non_neg_integer(), size: non_neg_integer() }
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec clear() :: :ok
Clears all cached entries.
Gets a cached value by key, returning {:hit, value} or :miss.
Gets a cached value, allowing stale data within grace period.
Returns {:hit, value} or {:stale, value} or :miss.
@spec invalidate(term()) :: :ok
Invalidates a specific cache entry.
@spec invalidate_pattern(term()) :: :ok
Invalidates entries matching a key prefix/pattern.
Stores a value in the cache with TTL.
Generates a cache key for recall operations.
Generates a cache key for reflect operations.
@spec start_link(keyword()) :: GenServer.on_start()
Starts the cache GenServer.
@spec stats() :: stats()
Returns cache statistics.