# `Bandera.Store.Cache`

ETS read cache for flags. Always started; bypassed by the store when the cache
is disabled (so the cache can be toggled at runtime without races). The TTL is
read from the runtime `Bandera.Config` snapshot at lookup time.

Note: a TTL of `0` causes every entry to expire immediately on the next read
(it is not "no expiry"). To disable caching entirely, set `cache: [enabled: false]`.

# `bust`

```elixir
@spec bust(atom()) :: :ok
```

Evicts a single flag's cache entry. Used by cache-busting notifications.

## Examples

    iex> Bandera.Store.Cache.put(Bandera.Flag.new(:demo, []))
    iex> Bandera.Store.Cache.bust(:demo)
    :ok
    iex> Bandera.Store.Cache.get(:demo)
    {:miss, :not_found}

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `flush`

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

Evicts every cache entry.

## Examples

    iex> Bandera.Store.Cache.put(Bandera.Flag.new(:demo, []))
    iex> Bandera.Store.Cache.flush()
    :ok
    iex> Bandera.Store.Cache.get(:demo)
    {:miss, :not_found}

# `get`

```elixir
@spec get(atom()) :: {:ok, Bandera.Flag.t()} | {:miss, :not_found | :expired}
```

Reads a flag from the cache.

Returns `{:ok, flag}` on a live hit, or `{:miss, :not_found}` / `{:miss, :expired}`
so the caller can fall through to the persistent store. Expiry is evaluated against
the current `Bandera.Config.cache_ttl/0` at read time.

## Examples

    iex> Bandera.Store.Cache.get(:absent)
    {:miss, :not_found}

    iex> Bandera.Store.Cache.put(Bandera.Flag.new(:demo, []))
    iex> Bandera.Store.Cache.get(:demo)
    {:ok, %Bandera.Flag{name: :demo, gates: []}}

# `put`

```elixir
@spec put(Bandera.Flag.t()) :: Bandera.Flag.t()
```

Caches `flag` with a fresh timestamp and returns it unchanged (for pipelining).

## Examples

    iex> Bandera.Store.Cache.put(Bandera.Flag.new(:demo, []))
    %Bandera.Flag{name: :demo, gates: []}

# `start_link`

```elixir
@spec start_link(keyword()) :: GenServer.on_start()
```

Starts the cache GenServer (which owns the backing ETS table) under its module name.

---

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