Mnemonix v0.7.0 Mnemonix.Store.Server

Bridges Mnemonix.Features with underlying Mnemonix.Stores.

Summary

Types

A two-tuple describing a store type and options to start it

Options used to start a Mnemonix.Store.Server

Functions

Delegates Mnemonix.Feature functions to the underlying store behaviours

Prepares the underlying store impl for usage with supplied options

Starts a new Mnemonix.Store.Server using the provided store impl and options

Starts a new Mnemonix.Store.Server using store impl, store options, and server options

Cleans up the underlying store on termination

Types

config()

A two-tuple describing a store type and options to start it.

options()
options :: [otp_app: atom, store: Mnemonix.Store.options, server: GenServer.opts]

Options used to start a Mnemonix.Store.Server.

Functions

handle_call(msg, from, state)
handle_call(request :: term, GenServer.from, Mnemonix.Store.t) ::
  {:reply, reply, new_store} |
  {:reply, reply, new_store, timeout | :hibernate} |
  {:noreply, new_store} |
  {:noreply, new_store, timeout | :hibernate} |
  {:stop, reason, reply, new_store} |
  {:stop, reason, new_store} when reply: term, new_store: Mnemonix.Store.t, reason: term, timeout: pos_integer

Delegates Mnemonix.Feature functions to the underlying store behaviours.

init(args)
init({Mnemonix.Store.Behaviour.t, Mnemonix.Store.options}) ::
  {:ok, Mnemonix.Store.t} |
  :ignore |
  {:stop, reason :: term}

Prepares the underlying store impl for usage with supplied options.

Invokes the c:Mnemonix.Core.Behaviour.setup/1 and c:Mnemonix.Expiry.Behaviour.setup_expiry/1 callbacks.

start_link(impl, options \\ [])
start_link(Mnemonix.Store.Behaviour.t, options) :: GenServer.on_start

Starts a new Mnemonix.Store.Server using the provided store impl and options.

Available options are:

  • :store

    Options to be given to the store on setup. Study the store impl for more information.

  • :server

    A keyword list of options to be given to GenServer.

  • :otp_app

    Fetches more options for the above from config otp_app, module, options, and merges them together. If no otp_app is specified, will check under config :mnemonix, module, options for default options. Options supplied directly to this function always take precedence over any found in your configuration.

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

Examples

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

iex> options = [store: [initial: %{foo: :bar}], server: [name: StoreCache]]
iex> {:ok, _store} = Mnemonix.Store.Server.start_link(Mnemonix.Stores.Map, options)
iex> Mnemonix.get(StoreCache, :foo)
:bar
start_link(impl, store, server)
start_link(Mnemonix.Store.Behaviour.t, Mnemonix.Store.options, GenServer.opts) :: GenServer.on_start

Starts a new Mnemonix.Store.Server using store impl, store options, and server options.

store will be given to the store on setup. Study the store impl for more information.

server options be given to GenServer.start_link/3.

No application configuration checking option merging is performed.

Examples

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

iex> store = [initial: %{foo: :bar}]
iex> server = [name: StoreCache]
iex> {:ok, _store} = Mnemonix.Store.Server.start_link(Mnemonix.Stores.Map, store, server)
iex> Mnemonix.get(StoreCache, :foo)
:bar
terminate(reason, arg2)
terminate(reason, Mnemonix.Store.t) :: reason when reason: :normal | :shutdown | {:shutdown, term} | term

Cleans up the underlying store on termination.

Invokes the c:Mnemonix.Lifecycle.Behaviour.teardown/2 callback.