Mnemonix v0.2.0 Mnemonix.Map.Store

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.Map.Store.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

Constructs a map to store data

Starts a new Mnemonix.Store using the Mnemonix.Map.Store adapter with init opts

Functions

delete(store, key)
delete(store, key) :: {:ok, store}

Callback implementation for Mnemonix.Store.Behaviour.delete/2.

fetch(store, key)
fetch(store, key) :: {:ok, store, {:ok, value} | :error}

Callback implementation for Mnemonix.Store.Behaviour.fetch/2.

init(opts)
init(opts) :: {:ok, state}

Constructs a map to store data.

Options

  • initial: An existing map to start the store with. Default: %{}
put(store, key, value)
put(store, key, Mnemonix.Store.value) :: {:ok, store}

Callback implementation for Mnemonix.Store.Behaviour.put/3.

start_link(opts \\ [])
start_link(GenServer.options) :: {:ok, GenServer.server}

Starts a new Mnemonix.Store using the Mnemonix.Map.Store adapter.

If you wish to pass configuration options to the adapter 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.Map.Store.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
start_link(init, opts)

Starts a new Mnemonix.Store using the Mnemonix.Map.Store adapter with init opts.

The returned GenServer.server/0 reference can be used as the primary argument to the Mnemonix API.