Mnemonix v0.5.0 Mnemonix.Stores.DETS

A Mnemonix.Store that uses a DETS table to store state.

iex> {:ok, store} = Mnemonix.Stores.DETS.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

Creates a new DETS table to store state

Starts a new Mnemonix.Store using the Mnemonix.Stores.DETS module

Starts a new Mnemonix.Store using the Mnemonix.Stores.DETS module with init opts

Functions

delete(store, key)
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(store, key)
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(store, key, value)
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.

setup(opts)
setup(Mnemonix.Store.options) ::
  {:ok, state :: term} |
  {:stop, reason :: any}

Creates a new DETS table to store state.

If the DETS file already exists, will use the contents of that table.

Options

  • table: Name of the table to connect to.

    Default: Mnemonix.Stores.DETS.Table

The rest of the options are passed into :dets.open_file/2 verbaitm, except for type:, which will always be :set.

start_link(opts \\ [])

Starts a new Mnemonix.Store using the Mnemonix.Stores.DETS 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.DETS.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

Starts a new Mnemonix.Store using the Mnemonix.Stores.DETS module with init opts.

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