# `Macaw.Live.Proxy.Cache`
[🔗](https://github.com/dcoai/macaw_live/blob/v0.1.0/lib/macaw/live/proxy/cache.ex#L1)

The proxy's cache by filled upstream URL (spec/06 §1.5), a behavior over an argument, so
a host of several nodes plugs a shared one. A host chooses it with the supervisor's
`proxy_cache:` option, `{module, arg}`; `Macaw.Live.Proxy.Cache.Memory`, the default, is
bounded by entries and bytes and drops the least recently used. A cache module
exporting `child_spec/1` is started under the supervisor with its argument and
`name: <live>.ProxyCache`, and that argument is the one its callbacks are given.

**Only the upstream's freshness is cached** (`Macaw.Live.Proxy.freshness/1`): a response
with `no-store`, `private` or `no-cache`, or with no freshness, is never put, and a fresh
entry is answered without a fetch until `fresh_until_ms`, on the wall clock in
milliseconds.

# `entry`

```elixir
@type entry() :: %{type: String.t(), body: binary(), fresh_until: integer()}
```

A cached answer: its checked type and body, and when it stops being fresh.

# `get`

```elixir
@callback get(arg :: term(), url :: String.t(), now_ms :: integer()) ::
  {:ok, entry()} | :miss
```

The fresh entry of `url` at `now_ms`: `{:ok, entry}`, or `:miss` for none or a stale one.

# `put`

```elixir
@callback put(
  arg :: term(),
  url :: String.t(),
  entry :: map(),
  fresh_until_ms :: integer()
) :: :ok
```

Holds `entry` for `url` until `fresh_until_ms`: `:ok`.

---

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