Macaw.Live.Proxy.Cache behaviour (macaw_live v0.1.0)

Copy Markdown View Source

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.

Summary

Types

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

Callbacks

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

Holds entry for url until fresh_until_ms: :ok.

Types

entry()

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

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

Callbacks

get(arg, url, now_ms)

@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(arg, url, entry, fresh_until_ms)

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

Holds entry for url until fresh_until_ms: :ok.