Alternera.Plugin.Provisional.Cache (alternera_plugin_sdk v0.9.0)

Copy Markdown View Source

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.

Summary

Functions

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.

The value kept under key, or :miss.

Keeps value under key. Takes :max_entries.

Functions

fetch(name, key, build, opts \\ [])

@spec fetch(String.t(), term(), (-> 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(name, key)

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

The value kept under key, or :miss.

put(name, key, value, opts \\ [])

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

Keeps value under key. Takes :max_entries.