Mnemonix v0.4.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.fetch(Store, :foo)
{:ok, "bar"}
iex> Mnemonix.delete(Store, :foo)
iex> Mnemonix.fetch(Store, :foo)
:error

Summary

Types

The return value of a bump operation

A module implementing Mnemonix.Store.Behaviour

Adapter and optional initialization options for start_link/1

Keys allowed in Mnemonix entries

Options supplied to c:Mnemonix.Store.Lifecycle.Behaviour.setup/1 to initialize the impl/0

Internal state specific to the impl/0

t()

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

The number of milliseconds an entry will be allowed to exist

Values allowed in Mnemonix entries

Functions

Prepares the underlying store type for usage with supplied options

Starts a new Mnemonix.Store using impl

Starts a new Mnemonix.Store using impl with opts

Types

bump_op()
bump_op :: :ok | {:error, :no_integer}

The return value of a bump operation.

impl()

A module implementing Mnemonix.Store.Behaviour.

init()
init :: impl | {impl, opts}

Adapter and optional initialization options for start_link/1.

key()
key :: term

Keys allowed in Mnemonix entries.

opts()

Options supplied to c:Mnemonix.Store.Lifecycle.Behaviour.setup/1 to initialize the impl/0.

state()
state :: term

Internal state specific to the impl/0.

t()
t :: %Mnemonix.Store{expiry: :native | pid, impl: impl, opts: opts, state: state}

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

ttl()
ttl :: non_neg_integer | nil

The number of milliseconds an entry will be allowed to exist.

value()
value :: term

Values allowed in Mnemonix entries.

Functions

init(args)
init({impl, opts}) ::
  {:ok, t} |
  :ignore |
  {:stop, reason :: term}

Prepares the underlying store type for usage with supplied options.

Invokes the setup/1 callback and initialization callbacks required by store utilities:

  • c:Mnemonix.Expiry.Behaviour.setup_expiry/1
start_link(init)
start_link(impl) :: GenServer.on_start
start_link({impl, opts}) :: GenServer.on_start

Starts a new Mnemonix.Store using impl.

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 impl 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