Macaw.Live.Assets.Store behaviour (macaw_live v0.1.0)

Copy Markdown View Source

Where the runtime keeps what it registers at mount (spec/06 §2.1): generated stylesheets and proxy routes, a behavior over an argument, so a host of several nodes plugs a shared store. Copied from visualize's Visualize.Sheets table and made a behavior.

A host chooses it with the supervisor's assets: option, {module, arg}; Macaw.Live.Assets.Store.Memory, the default, is an ETS table the supervisor owns, bounded at 4,096 entries. A store module exporting child_spec/1 is started under the supervisor with its argument and name: <live>.Assets, and that argument, the name in it, is the one its callbacks are given.

Keys are the runtime's: {:stylesheet, hex} for a sheet, hex the SHA-256 of its bytes, and {:route, component, name, digest} for a proxy route. A key's value never changes, since each is named by its content, so putting a key already held is a no-op.

Summary

Callbacks

The value held under key: {:ok, value}, or :error for one it doesn't hold.

Holds value under key: :ok, or {:error, reason} for a store that couldn't.

Callbacks

fetch(arg, key)

@callback fetch(arg :: term(), key :: term()) :: {:ok, term()} | :error

The value held under key: {:ok, value}, or :error for one it doesn't hold.

put(arg, key, value)

@callback put(arg :: term(), key :: term(), value :: term()) :: :ok | {:error, term()}

Holds value under key: :ok, or {:error, reason} for a store that couldn't.