PayDayLoan.Backend behaviour (pay_day_loan v0.8.2)
Defines the PDL backend behaviour.
The backend is responsible for allowing us to access the cached value
for a given key. PayDayLoan's EtsBackend
module is used by default, and
is built with a process cache in mind. You could use the Backend
behaviour to implement, for example, a Redis or mnesia backend.
Link to this section Summary
Callbacks
Delete a key from the cache
Retrieve a value from the cache
Should return a list of keys in the cache
Insert a value into the cache
Should execute a reduce operation over the key/value pairs in the cache.
Called during supervisor initialization - use this callback to initialize
your backend if needed. Must return :ok
.
Should return the number of keys in the cache
Should return a list of values in the cache
Link to this section Callbacks
delete(t, key)
@callback delete(PayDayLoan.t(), PayDayLoan.key()) :: :ok
Delete a key from the cache
Must return :ok
get(t, key)
@callback get(PayDayLoan.t(), PayDayLoan.key()) :: {:ok, term()} | {:error, PayDayLoan.error()}
Retrieve a value from the cache
Should return {:error, :not_found}
if the value is not found and
{:ok, value}
otherwise.
keys(t)
@callback keys(PayDayLoan.t()) :: [PayDayLoan.key()]
Should return a list of keys in the cache
put(t, key, term)
@callback put(PayDayLoan.t(), PayDayLoan.key(), term()) :: :ok
Insert a value into the cache
Must return :ok
reduce(t, acc0, reducer)
@callback reduce( PayDayLoan.t(), acc0 :: term(), reducer :: ({PayDayLoan.key(), term()}, term() -> term()) ) :: term()
Should execute a reduce operation over the key/value pairs in the cache.
The reducer function should take arguments in the form
({key, value}, accumulator)
and return the new accumulator value - i.e.,
it should operate as Enum.reduce/3
would when given a map.
setup t
@callback setup(PayDayLoan.t()) :: :ok
Called during supervisor initialization - use this callback to initialize
your backend if needed. Must return :ok
.
size(t)
@callback size(PayDayLoan.t()) :: non_neg_integer()
Should return the number of keys in the cache
values(t)
@callback values(PayDayLoan.t()) :: [term()]
Should return a list of values in the cache