Operate v0.1.0-beta.1 Operate.Cache behaviour View Source
Operate cache specification.
A cache is responsible for storing and retrieving tapes and ops from a cache, and if necessary instructing an adapter to fetch items from a data source.
Operate comes bundled with a ConCache
ETS cache, although by default runs
without any caching.
Creating a cache
A cache must implement both of the following callbacks:
fetch_tx/3
- function that takes a txid and returns aOperate.BPU.Transaction.t/0
fetch_ops/3
- function that takes a list of Op references and returns a list ofOperate.Op.t/0
functions.
The third argument in both functions is a tuple containing the adapter module and a keyword list of options to pass to the adapter.
defmodule MyCache do
use Operate.Cache
def fetch_tx(txid, opts, {adapter, adapter_opts}) do
ttl = Keyword.get(opts, :ttl, 3600)
Cache.fetch_or_store(txid, ttl: ttl, fn ->
adapter.fetch_tx(txid, adapter_opts)
end)
end
end
Using the above example, Operate can be configured with:
{Operate, [
cache: {MyCache, [ttl: 3600]}
]}
Link to this section Summary
Callbacks
Loads Ops from the cache by the given procedure referneces, or delegates
the job to the specified adapter. Returns the result in an :ok
/ :error
tuple pair.
As fetch_ops/3
, but returns the result or raises an exception.
Loads a transaction from the cache by the given txid, or delegates to job to
the specified adapter. Returns the result in an :ok
/ :error
tuple pair.
As fetch_tx/3
, but returns the transaction or raises an exception.
Link to this section Callbacks
Loads Ops from the cache by the given procedure referneces, or delegates
the job to the specified adapter. Returns the result in an :ok
/ :error
tuple pair.
fetch_ops!(list, keyword, {})
View Sourcefetch_ops!(list(), keyword(), {module(), keyword()}) :: [Operate.Op.t(), ...]
As fetch_ops/3
, but returns the result or raises an exception.
Loads a transaction from the cache by the given txid, or delegates to job to
the specified adapter. Returns the result in an :ok
/ :error
tuple pair.
fetch_tx!(arg1, keyword, {})
View Sourcefetch_tx!(String.t(), keyword(), {module(), keyword()}) :: Operate.Tape.t()
As fetch_tx/3
, but returns the transaction or raises an exception.