pay_day_loan v0.5.1 PayDayLoan.Backend behaviour

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.

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

Callbacks

delete(arg0, arg1)
delete(PayDayLoan.t, PayDayLoan.key) :: :ok

Delete a key from the cache

Must return :ok

get(arg0, arg1)
get(PayDayLoan.t, PayDayLoan.key) ::
  {:ok, term} |
  {:error, :not_found}

Retrieve a value from the cache

Should return {:error, :not_found} if the value is not found and {:ok, value} otherwise.

keys(arg0)

Should return a list of keys in the cache

put(arg0, arg1, term)
put(PayDayLoan.t, PayDayLoan.key, term) :: :ok

Insert a value into the cache

Must return :ok

reduce(arg0, acc0, reducer)
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(arg0)
setup(PayDayLoan.t) :: :ok

Called during supervisor initialization - use this callback to initialize your backend if needed. Must return :ok.

size(arg0)
size(PayDayLoan.t) :: non_neg_integer

Should return the number of keys in the cache

values(arg0)
values(PayDayLoan.t) :: [term]

Should return a list of values in the cache