# `Redis.Cache.Store`
[🔗](https://github.com/joshrotenberg/redis_ex/blob/v0.7.1/lib/redis/cache/store.ex#L1)

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`, `0` for unlimited)
  * `:eviction_policy` - `:lru` or `:fifo` (default: `:lru`)

# `eviction_policy`

```elixir
@type eviction_policy() :: :lru | :fifo
```

# `t`

```elixir
@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()
}
```

# `destroy`

```elixir
@spec destroy(t()) :: :ok
```

Destroys the cache store (deletes the ETS tables).

# `flush`

```elixir
@spec flush(t()) :: t()
```

Clears the entire cache.

# `get`

```elixir
@spec get(t(), term()) :: {:hit, term(), t()} | {:miss, t()}
```

Gets a value from the cache. Returns `{:hit, value, store}` or `{:miss, store}`.

# `init`

```elixir
@spec init(keyword()) :: {:ok, t()}
```

Initializes the store from options. Implements `Redis.Cache.Backend.init/1`.

# `invalidate`

```elixir
@spec invalidate(t(), [String.t()] | nil) :: t()
```

Invalidates one or more keys. Called when Redis pushes invalidation.

# `invalidate_refs`

```elixir
@spec invalidate_refs(t(), [String.t()] | nil) :: t()
```

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.

# `new`

```elixir
@spec new(
  atom(),
  keyword()
) :: t()
```

Creates a new cache store backed by ETS tables.

# `put`

```elixir
@spec put(t(), term(), term(), non_neg_integer() | nil) :: t()
```

Puts a value in the cache with optional TTL in milliseconds.

# `put_with_ref`

```elixir
@spec put_with_ref(t(), term(), String.t(), term(), non_neg_integer() | nil) :: t()
```

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.

# `stats`

```elixir
@spec stats(t()) :: map()
```

Returns cache statistics.

# `sweep_expired`

```elixir
@spec sweep_expired(t()) :: t()
```

Removes expired entries from the cache.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
