AbsintheCacheFairy.Behaviour behaviour (absinthe_cache_fairy v0.2.0)

Behaviour that the cache needs to conform to.

TODO: Write more docs

Link to this section Summary

Callbacks

Get the value for the given key from the cache.

Get the value for the given key from the cache. If there is no record with this key, execute fun, store its value under the key key if and only if it is not an error and return in. If there is more than one query for that key, fun should be executed only once and the rest of the queries will wait until the result. is ready.

Put a query document in the cache with the key as cache key.

Link to this section Types

@type cache() :: atom()
@type error() :: String.t()
@type hash() :: String.t()
@type key() :: hash() | {atom(), hash()} | {non_neg_integer(), non_neg_integer()}
@type size_type() :: :megabytes
Link to this type

stored_value()

@type stored_value() :: any()

Link to this section Callbacks

Link to this callback

clear_all(cache)

@callback clear_all(cache()) :: :ok
Link to this callback

get(cache, hash)

@callback get(cache(), hash()) :: {:ok, any()} | {:error, error()} | nil

Get the value for the given key from the cache.

Link to this callback

get_or_store(cache, key, function)

(optional)
@callback get_or_store(cache(), key(), (... -> any())) ::
  {:ok, stored_value()} | {:error, error()}
Link to this callback

get_or_store(cache, key, function, function)

(optional)
@callback get_or_store(cache(), key(), (... -> any()), (... -> any())) ::
  {:ok, stored_value()} | {:error, error()}

Get the value for the given key from the cache. If there is no record with this key, execute fun, store its value under the key key if and only if it is not an error and return in. If there is more than one query for that key, fun should be executed only once and the rest of the queries will wait until the result. is ready.

Link to this callback

size(cache, size_type)

@callback size(cache(), size_type()) :: float()
Link to this callback

store(cache, key, stored_value)

@callback store(cache(), key(), stored_value()) :: :ok | {:error, error()}

Put a query document in the cache with the key as cache key.