Mnemonix v0.2.0 Mnemonix.Store

Normalizes access to different key-value stores behind a GenServer.

Once a store has been started, you can use Mnemonix methods to manipulate it:

iex> Mnemonix.Store.start_link(Mnemonix.Map.Store, name: Store)
iex> Mnemonix.put(Store, :foo, "bar")
iex> Mnemonix.get(Store, :foo)
"bar"
iex> Mnemonix.delete(Store, :foo)
iex> Mnemonix.get(Store, :foo)
nil

Summary

Types

A module implementing Mnemonix.Store.Behaviour

Adapter and optional initialization options for start_link/1

Keys allowed in Mnemonix entries

Options supplied to Mnemonix.Store.Behaviour.init/1 to initialize the adapter/0

Internal state specific to the adapter/0

t()

Container for adapter/0, opts/0, and state/0

Values allowed in Mnemonix entries

Functions

Starts a new Mnemonix.Store using adapter

Starts a new Mnemonix.Store using adapter with opts

Types

adapter()

A module implementing Mnemonix.Store.Behaviour.

init()

Adapter and optional initialization options for start_link/1.

key()
key :: term

Keys allowed in Mnemonix entries.

opts()

Options supplied to Mnemonix.Store.Behaviour.init/1 to initialize the adapter/0.

state()
state :: term

Internal state specific to the adapter/0.

t()
t :: %Mnemonix.Store{adapter: adapter, opts: opts, state: state}

Container for adapter/0, opts/0, and state/0.

value()
value :: term

Values allowed in Mnemonix entries.

Functions

start_link(init)
start_link(adapter) :: GenServer.on_start
start_link({adapter, opts}) :: GenServer.on_start

Starts a new Mnemonix.Store using adapter.

If you wish to pass options to GenServer.start_link/3, use start_link/2.

The returned GenServer.server/0 reference can be used in the Mnemonix API.

Examples

iex> {:ok, store} = Mnemonix.Store.start_link(Mnemonix.Map.Store) iex> Mnemonix.put(store, :foo, :bar) iex> Mnemonix.get(store, :foo) :bar

iex> {:ok, store} = Mnemonix.Store.start_link({Mnemonix.Map.Store, initial: %{foo: :bar}}) iex> Mnemonix.get(store, :foo) :bar

start_link(init, opts)

Starts a new Mnemonix.Store using adapter with opts.

The returned GenServer.server/0 reference can be used in the Mnemonix API.

Examples

iex> {:ok, _store} = Mnemonix.Store.start_link(Mnemonix.Map.Store, name: StoreCache)
iex> Mnemonix.put(StoreCache, :foo, :bar)
iex> Mnemonix.get(StoreCache, :foo)
:bar

iex> {:ok, _store} = Mnemonix.Store.start_link({Mnemonix.Map.Store, initial: %{foo: :bar}}, name: OtherCache)
iex> Mnemonix.get(OtherCache, :foo)
:bar