# `Ussd.Cache`
[🔗](https://github.com/spesohq/ussd/blob/main/lib/ussd/cache.ex#L1)

The storage contract `Ussd.Record` (and therefore session state) is built on.

Ship your own implementation (backed by Redis, `:cachex`, Mnesia, ...) and point
`Ussd.Record` at it via `config :ussd, :cache, MyApp.UssdCache`, or via
`Ussd.use_store/2` per-request. The default, `Ussd.Cache.ETS`, is process-local and
fine for a single node; anything multi-node needs a shared backend.

# `key`

```elixir
@type key() :: String.t()
```

# `ttl`

```elixir
@type ttl() :: pos_integer() | nil
```

# `decrement`

```elixir
@callback decrement(key(), amount :: integer()) :: integer()
```

Subtracts `amount` from `key`, treating an unset key as starting from 0, and returns the new value.

# `forget`

```elixir
@callback forget(key()) :: :ok
```

Deletes `key`.

# `get`

```elixir
@callback get(key(), default :: term()) :: term()
```

Reads `key`, or `default` if it's unset or has expired.

# `has?`

```elixir
@callback has?(key()) :: boolean()
```

Whether `key` is currently set (and not expired).

# `increment`

```elixir
@callback increment(key(), amount :: integer()) :: integer()
```

Adds `amount` to `key`, treating an unset key as starting from 0, and returns the new value.

# `set`

```elixir
@callback set(key(), value :: term(), ttl()) :: :ok
```

Stores `value` under `key`. `ttl`, in seconds, is `nil` when the value should never expire on its own.

---

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