Mnemonix v0.6.2 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

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

Starts a new Mnemonix.Store.Server using the Mnemonix.Stores.ETS module with options

Starts a new Mnemonix.Store.Server using the Mnemonix.Stores.ETS with store and server options

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 ETS table to store state.

Options

  • table: Name of the table to create.

    Default: Mnemonix.Stores.ETS.Table

  • named: ETS named table option

    Default: false

    If making a non-public table it’s reccommened to use this option, so that the table name can be used outside of this store.

  • privacy: ETS privacy option - :public | :protected | :private

    Default: :private

  • heir: ETS heir option - {pid, any} | nil

    Default: nil

  • transactional: Whether or not to perform transactional reads or writes.

Allowed: :reads | :writes | :both | nil

Default: nil

  • compressed: Whether or not to compress the values being stored.

    Default: false

start_link(options \\ [])

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 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"
start_link(store, server)

Starts a new Mnemonix.Store.Server using the Mnemonix.Stores.ETS with store and server options.

The options are the same as described in Mnemonix.Store.Server.start_link/3.

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"