AshCache.Store.Adapter behaviour (AshCache v0.1.0)

Copy Markdown View Source

Behaviour every AshCache storage adapter implements.

Deliberately the plainest possible key/value contract, so an adapter already written against another cache facade ports one-to-one. A miss is {:ok, nil}, never an error tuple.

Summary

Callbacks

clear(store)

@callback clear(store :: atom()) :: :ok | {:error, term()}

delete(store, key)

@callback delete(store :: atom(), key :: term()) :: :ok | {:error, term()}

get(store, key)

@callback get(store :: atom(), key :: term()) :: {:ok, term()} | {:error, term()}

put(store, key, value, opts)

@callback put(store :: atom(), key :: term(), value :: term(), opts :: keyword()) ::
  :ok | {:error, term()}

Stores a value. Recognised options:

  • :ttl — milliseconds, or :infinity
  • :never_evict — exempt this entry from any capacity bound the adapter enforces. For metadata an adapter must not drop on its own, such as the version counters cache invalidation reads. Adapters without a bound ignore it.