Mnemonix v0.2.0 Mnemonix.Store.Behaviour behaviour
Required and optional functions Mnemonix.Store adapters must implement.
Optional callbacks have default implementations in terms of the required ones, but are overridable so that adapters can offer optimized versions where possible.
Summary
Callbacks
Removes the entry under key in store
Retrievs the value of the entry under key in store
Fetches the value for specific key
Gets the value for a specific key
Gets the value for a specific key with default
Gets the value from key and updates it, all in one pass
Gets the value from key and updates it. Raises if there is no key
Gets the value for a specific key
Returns whether a given key exists in the given store
Prepares the underlying store type for usage with supplied options
Returns and removes the value associated with key in store
Returns and removes the value associated with key in store with default
Lazily returns and removes the value associated with key in store
Creates a new entry for value under key in store
Puts the given value under key unless the entry key
already exists
Evaluates fun and puts the result under key
in store unless key is already present
Updates the key in store with the given function
Updates the key with the given function
Callbacks
Removes the entry under key in store.
If the key does not exist, the contents of store will be unaffected.
Retrievs the value of the entry under key in store.
If the key does not exist, returns :error, otherwise
returns {:ok, value}.
Fetches the value for specific key.
If key does not exist, triggers a KeyError.
Gets the value for a specific key.
If key does not exist, returns nil.
get(store, key, value) ::
{:ok, store, value} |
{:raise, exception, info}
Gets the value for a specific key with default.
If key does not exist, returns default.
get_and_update(store, key, (... -> any)) ::
{:ok, store, value} |
{:raise, exception, info}
Gets the value from key and updates it, all in one pass.
This fun argument receives the value of key (or nil if key
is not present) and must return a two-element tuple: the “get” value
(the retrieved value, which can be operated on before being returned)
and the new value to be stored under key. The fun may also
return :pop, implying the current value shall be removed
from store and returned.
The returned value is a tuple with the “get” value returned by
fun and a reference to the store with the updated value under key.
get_and_update!(store, key, (... -> any)) ::
{:ok, store, value} |
{:raise, exception, info}
Gets the value from key and updates it. Raises if there is no key.
This fun argument receives the value of key and must return a
two-element tuple: the “get” value (the retrieved value, which can be
operated on before being returned) and the new value to be stored under
key.
The returned value is a tuple with the “get” value returned by fun and a
a reference to the store with the updated value under key.
get_lazy(store, key, (... -> any)) ::
{:ok, store, value} |
{:raise, exception, info}
Gets the value for a specific key.
If key does not exist, lazily evaluates fun and returns its result.
This is useful if the default value is very expensive to calculate or generally difficult to setup and teardown again.
has_key?(store, key) ::
{:ok, store, boolean} |
{:raise, exception, info}
Returns whether a given key exists in the given store.
init(Mnemonix.Store.opts) :: {:ok, Mnemonix.Store.state} | {:ok, Mnemonix.Store.state, timeout | :hibernate} | :ignore | {:stop, reason :: term}
Prepares the underlying store type for usage with supplied options.
Returns internal state the adapter can use to access the underlying store to perform operations on data.
Returns and removes the value associated with key in store.
If no value is associated with the key, nil is returned.
pop(store, key, value) ::
{:ok, store, value} |
{:raise, exception, info}
Returns and removes the value associated with key in store with default.
If no value is associated with the key but default is given,
that will be returned instead without touching the store.
pop_lazy(store, key, (... -> any)) ::
{:ok, store, value} |
{:raise, exception, info}
Lazily returns and removes the value associated with key in store.
This is useful if the default value is very expensive to calculate or generally difficult to setup and teardown again.
Creates a new entry for value under key in store.
put_new(store, key, value) ::
{:ok, store} |
{:raise, exception, info}
Puts the given value under key unless the entry key
already exists.
put_new_lazy(store, key, (... -> any)) ::
{:ok, store} |
{:raise, exception, info}
Evaluates fun and puts the result under key
in store unless key is already present.
This is useful if the value is very expensive to calculate or generally difficult to setup and teardown again.
teardown(reason, store) ::
{:ok, reason} |
{:error, reason} when reason: :normal | :shutdown | {:shutdown, term} | term
update(store, key, value, (... -> any)) ::
{:ok, store} |
{:raise, exception, info}
Updates the key in store with the given function.
If the key does not exist, inserts the given initial value.
update!(store, key, (... -> any)) ::
{:ok, store} |
{:raise, exception, info}
Updates the key with the given function.
If the key does not exist, triggers a KeyError.