ETS-backed cache store for client-side caching.
This is the default implementation of Redis.Cache.Backend. Stores
key -> value mappings with optional TTL, bounded size, and configurable
eviction policy. Tracks hits, misses, and evictions for observability.
Options
:max_entries- maximum number of entries (default:10_000,0for unlimited):eviction_policy-:lruor:fifo(default::lru)
Summary
Functions
Destroys the cache store (deletes the ETS tables).
Clears the entire cache.
Gets a value from the cache. Returns {:hit, value, store} or {:miss, store}.
Initializes the store from options. Implements Redis.Cache.Backend.init/1.
Invalidates one or more keys. Called when Redis pushes invalidation.
Invalidates all cache entries that reference the given Redis key(s).
Creates a new cache store backed by ETS tables.
Puts a value in the cache with optional TTL in milliseconds.
Puts a value in the cache and records a ref from redis_key to cache_key.
Returns cache statistics.
Removes expired entries from the cache.
Types
@type eviction_policy() :: :lru | :fifo
@type t() :: %Redis.Cache.Store{ eviction_policy: eviction_policy(), evictions: non_neg_integer(), hits: non_neg_integer(), index_table: :ets.tid(), max_entries: non_neg_integer(), misses: non_neg_integer(), refs_table: :ets.tid(), stores: non_neg_integer(), table: :ets.tid() }
Functions
@spec destroy(t()) :: :ok
Destroys the cache store (deletes the ETS tables).
Clears the entire cache.
Gets a value from the cache. Returns {:hit, value, store} or {:miss, store}.
Initializes the store from options. Implements Redis.Cache.Backend.init/1.
Invalidates one or more keys. Called when Redis pushes invalidation.
Invalidates all cache entries that reference the given Redis key(s).
Looks up the refs table to find cache keys that depend on each Redis key, invalidates them, and cleans up the ref entries.
Creates a new cache store backed by ETS tables.
@spec put(t(), term(), term(), non_neg_integer() | nil) :: t()
Puts a value in the cache with optional TTL in milliseconds.
Puts a value in the cache and records a ref from redis_key to cache_key.
When redis_key is later invalidated via invalidate_refs/2, all cache
entries that reference it are removed.
Returns cache statistics.
Removes expired entries from the cache.