Mnemonix v0.5.0 Mnemonix.Stores.Map
A Mnemonix.Store
that uses a map to store state.
Intended to be an example for implementing the Mnemonix.Store.Behaviour
and
experimenting with the Mnemonix
API rather than production usage.
It intentionally doesn’t override any optional callback with native versions so that the default implementations can be easily tested.
iex> {:ok, store} = Mnemonix.Stores.Map.start_link
iex> Mnemonix.put(store, :foo, "bar")
iex> Mnemonix.get(store, :foo)
"bar"
iex> Mnemonix.delete(store, :foo)
iex> Mnemonix.get(store, :foo)
nil
Summary
Functions
Callback implementation for c:Mnemonix.Store.Behaviours.Map.delete/2
Callback implementation for c:Mnemonix.Store.Behaviours.Map.fetch/2
Callback implementation for c:Mnemonix.Store.Behaviours.Map.put/3
Constructs a map to store data
Starts a new Mnemonix.Store
using the Mnemonix.Stores.Map
module
Starts a new Mnemonix.Store
using the Mnemonix.Stores.Map
module
with init
opts
Functions
delete(Mnemonix.Store.t, Mnemonix.key) :: {:ok, Mnemonix.Store.t} | Mnemonix.Store.Behaviour.exception
Callback implementation for c:Mnemonix.Store.Behaviours.Map.delete/2
.
fetch(Mnemonix.Store.t, Mnemonix.key) :: {:ok, Mnemonix.Store.t, {:ok, Mnemonix.value} | :error} | Mnemonix.Store.Behaviour.exception
Callback implementation for c:Mnemonix.Store.Behaviours.Map.fetch/2
.
put(Mnemonix.Store.t, Mnemonix.key, Mnemonix.Store.value) :: {:ok, Mnemonix.Store.t} | Mnemonix.Store.Behaviour.exception
Callback implementation for c:Mnemonix.Store.Behaviours.Map.put/3
.
Constructs a map to store data.
Options
initial:
An existing map to start the store with.Default:
%{}
Starts a new Mnemonix.Store
using the Mnemonix.Stores.Map
module.
If you wish to pass configuration options to the module instead,
use start_link/2
with an empty opts
list.
The returned GenServer.server/0
reference can be used as the primary
argument to the Mnemonix
API.
Examples
iex> {:ok, store} = Mnemonix.Stores.Map.start_link
iex> Mnemonix.put(store, :foo, "bar")
iex> Mnemonix.fetch(store, :foo)
{:ok, "bar"}
iex> Mnemonix.delete(store, :foo)
iex> Mnemonix.fetch(store, :foo)
:error
start_link(Mnemonix.Store.Server.options, GenServer.options) :: GenServer.on_start
Starts a new Mnemonix.Store
using the Mnemonix.Stores.Map
module
with init
opts.
The returned GenServer.server/0
reference can be used as the primary
argument to the Mnemonix
API.