pay_day_loan v0.5.1 PayDayLoan.EtsBackend
ETS-based backend capable of handling raw values, pids, or callbacks.
This is the default backend used by PayDayLoan and is designed for storing process ids. However, it can be used with raw values or callback functions.
With pids, special care is taken to keep the cache state consistent with
the “alive” state of the processes. If a process is found to be dead, the
key is removed from cache. The PayDayLoan.ProcessMonitor
process monitors
pids, and we check for alive-ness whenever we resolve a value.
If a callback is stored, then the callback is executed whenever we attempt
to resolve a value - e.g., on get
or reduce
or values
calls. The
callback must return a tuple with {:ok, value}
on success or
{:error, :not_found}
on failure.
The functions in this module are documented only to aid in understanding how the default backend works. They should not be called directly - only through the PDL API.
Summary
Functions
Remove a key from cache
Remove a value from cache
Get the value corresponding to the given key
Returns a list of all cached keys
Add a value to the cache and monitor it if it is a pid
Perform Enum.reduce on the ETS table
Setup callback, creates the underlying ETS table
Returns the number of cached keys
Returns a list of all cached values
Functions
Remove a key from cache
Remove a value from cache
Get the value corresponding to the given key
If the value is a process that is not alive, deletes the entry and returns
{:error, :not_found}
.
Returns a list of all cached keys
Add a value to the cache and monitor it if it is a pid.
reduce(PayDayLoan.t, term, ({PayDayLoan.key, pid}, term -> term)) :: term
Perform Enum.reduce on the ETS table
Setup callback, creates the underlying ETS table
Returns the number of cached keys
Returns a list of all cached values