# `Apero.Cache`
[🔗](https://github.com/Lorenzo-SF/apero/blob/3.0.0/lib/apero/cache.ex#L1)

Unified cache interface — ETS, Redis, Memcached.

Provides a consistent API for different cache backends via the
`Apero.Cache.Adapter` behaviour.

## Supported backends

  * `Apero.Cache.ETS` — in-memory ETS with TTL (built-in, no deps)
  * `Apero.Cache.Redis` — Redis via `redix` (optional dep)
  * `Apero.Cache.Memcached` — Memcached via `memcache` (optional dep)

## Usage

    # ETS (built-in)
    {:ok, pid} = Apero.Cache.start_link(Apero.Cache.ETS, name: :my_cache)
    Apero.Cache.put(:my_cache, "key", "value", ttl: 3600)
    Apero.Cache.get(:my_cache, "key") # => {:ok, "value"}

    # Redis
    Apero.Cache.put(:redis_cache, "key", "value")

# `cache_name`

```elixir
@type cache_name() :: atom() | pid()
```

# `delete`

```elixir
@spec delete(cache_name(), term()) :: :ok | {:error, term()}
```

Deletes a key.

# `fetch`

```elixir
@spec fetch(cache_name(), term(), (-&gt; term()), keyword()) ::
  {:ok, term()} | {:error, term()}
```

Fetches or computes a value (cache-aside pattern).

# `flush`

```elixir
@spec flush(cache_name()) :: :ok | {:error, term()}
```

Clears all keys.

# `get`

```elixir
@spec get(cache_name(), term()) :: {:ok, term()} | {:error, :not_found}
```

Retrieves a value. Returns `{:ok, value}` or `{:error, :not_found}`.

# `member?`

```elixir
@spec member?(cache_name(), term()) :: boolean()
```

Returns `true` if the key exists.

# `put`

```elixir
@spec put(cache_name(), term(), term(), keyword()) :: :ok | {:error, term()}
```

Stores a value. Optional `:ttl` in seconds.

# `size`

```elixir
@spec size(cache_name()) :: {:ok, non_neg_integer()} | {:error, term()}
```

Returns the number of keys.

# `start_link`

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

Starts a cache backend. Returns `{:ok, pid}`.

---

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