Mnemonix v0.8.0 Mnemonix.Stores.ETS
A Mnemonix.Store
that uses an ETS table to store state.
iex> {:ok, store} = Mnemonix.Stores.ETS.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
This store supports the functions in Mnemonix.Features.Enumerable
.
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 ETS table to store state using provided opts
Starts a new Mnemonix.Store.Server
using the Mnemonix.Stores.ETS
module with options
Starts a new Mnemonix.Store.Server
using Mnemonix.Stores.ETS
with store
and server
options
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
.
Creates a new ETS table to store state using provided opts
.
Options
table
: Name of the table to create.- Default:
Mnemonix.Stores.ETS.Table
- Default:
named
: ETS named table optionDefault:
false
Notes: If making a non-private table it’s reccommened to give your table a name.
privacy
: ETS privacy option -:public | :protected | :private
- Default:
:private
- Default:
heir
: ETS heir option -{pid, any} | nil
- Default: nil
concurrent
: Whether or not to optimize access for concurrent reads or writes.Allowed:
:reads | :writes | :both | false
Default:
false
compressed
: Whether or not to compress the values being stored.- Default:
false
- Default:
initial
: A map of key/value pairs to ensure are set on the DETS table at boot.- Default:
%{}
- Default:
Starts a new Mnemonix.Store.Server
using the Mnemonix.Stores.ETS
module with options
.
The options
are the same as described in Mnemonix.Store.Server.start_link/2
.
The :store
options are used in config/1
to start the store;
the :server
options are passed directly to GenServer.start_link/2
.
The returned GenServer.server/0
reference can be used as the primary
argument to the Mnemonix
API.
Examples
iex> {:ok, store} = Mnemonix.Stores.ETS.start_link()
iex> Mnemonix.put(store, "foo", "bar")
iex> Mnemonix.get(store, "foo")
"bar"
iex> {:ok, _store} = Mnemonix.Stores.ETS.start_link(server: [name: My.Mnemonix.Stores.ETS])
iex> Mnemonix.put(My.Mnemonix.Stores.ETS, "foo", "bar")
iex> Mnemonix.get(My.Mnemonix.Stores.ETS, "foo")
"bar"
start_link(Mnemonix.Store.Server.options, GenServer.options) :: GenServer.on_start
Starts a new Mnemonix.Store.Server
using Mnemonix.Stores.ETS
with store
and server
options.
The options are the same as described in Mnemonix.Store.Server.start_link/3
.
The store
options are used in config/1
to start the store;
the server
options are passed directly to GenServer.start_link/2
.
The returned GenServer.server/0
reference can be used as the primary
argument to the Mnemonix
API.
Examples
iex> {:ok, store} = Mnemonix.Stores.ETS.start_link([], [])
iex> Mnemonix.put(store, "foo", "bar")
iex> Mnemonix.get(store, "foo")
"bar"
iex> {:ok, _store} = Mnemonix.Stores.ETS.start_link([], [name: My.Mnemonix.Stores.ETS])
iex> Mnemonix.put(My.Mnemonix.Stores.ETS, "foo", "bar")
iex> Mnemonix.get(My.Mnemonix.Stores.ETS, "foo")
"bar"