Operate v0.1.0-beta.15 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:

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.

Loads a list of transactions from the cache by the given query map, or delegates to job to the specified adapter. Returns the result in an :ok / :error tuple pair.

As fetch_tx_by/3, but returns the result or raises an exception.

Link to this section Callbacks

Link to this callback

fetch_ops(list, keyword, {})

View Source

Specs

fetch_ops(list(), keyword(), {module(), keyword()}) ::
  {:ok, [Operate.Op.t(), ...]} | {:error, String.t()}

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.

Link to this callback

fetch_ops!(list, keyword, {})

View Source

Specs

fetch_ops!(list(), keyword(), {module(), keyword()}) :: [Operate.Op.t(), ...]

As fetch_ops/3, but returns the result or raises an exception.

Link to this callback

fetch_tx(arg1, keyword, {})

View Source

Specs

fetch_tx(String.t(), keyword(), {module(), keyword()}) ::
  {:ok, Operate.Tape.t()} | {:error, String.t()}

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.

Link to this callback

fetch_tx!(arg1, keyword, {})

View Source

Specs

fetch_tx!(String.t(), keyword(), {module(), keyword()}) :: Operate.Tape.t()

As fetch_tx/3, but returns the transaction or raises an exception.

Link to this callback

fetch_tx_by(map, keyword, {})

View Source

Specs

fetch_tx_by(map(), keyword(), {module(), keyword()}) ::
  {:ok, [Operate.Tape.t(), ...]} | {:error, String.t()}

Loads a list of transactions from the cache by the given query map, or delegates to job to the specified adapter. Returns the result in an :ok / :error tuple pair.

Link to this callback

fetch_tx_by!(map, keyword, {})

View Source

Specs

fetch_tx_by!(map(), keyword(), {module(), keyword()}) :: [Operate.Tape.t(), ...]

As fetch_tx_by/3, but returns the result or raises an exception.