# `Alternera.Plugin.Provisional.Cache`
[🔗](https://github.com/10e-ab/alternera-sdk/blob/v0.9.0/alternera_plugin_sdk/lib/alternera/plugin/provisional/cache.ex#L1)

Provisional: added for Validate, and a change to it needs a changelog line but
no new major (`docs/USER_PLUGINS_DESIGN.md`). The namespace has nothing to do
with the context's `:provisional?` key.

What a plugin compiled once and would rather not compile again, through
`Alternera.Plugin.Host`. It is for a value that can be rebuilt from its
key: an entry lives in this node's memory, can be gone on the next read, and a
write to the pipelines of a tenant does not touch it. Data that has to stay
belongs in `Alternera.Plugin.Provisional.Store`.

`name` is the plugin's own, usually its id, and is shared by every tenant. Two
tenants asking for the same key get the same value, so a key holds all a value
depends on, and a tenant goes into the key when the value is its own. A key is
any term and compared as a whole; two keys never share a value.

A name keeps about `:max_entries` entries, 512 by default. Past that they are
all dropped and rebuilt as they are used, since a tenant may be what writes the
keys. The count is not atomic and may run a little ahead, so the flush can come
early.

# `fetch`

```elixir
@spec fetch(String.t(), term(), (-&gt; value), keyword()) :: value when value: term()
```

The value kept under `key`, or what `build` returns, which is kept. What
`build` raises goes through and keeps nothing. Two processes that miss together
both build. Takes `:max_entries`.

# `get`

```elixir
@spec get(String.t(), term()) :: {:ok, term()} | :miss
```

The value kept under `key`, or `:miss`.

# `put`

```elixir
@spec put(String.t(), term(), term(), keyword()) :: :ok
```

Keeps `value` under `key`. Takes `:max_entries`.

---

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