Read only data store for Elixir: fast, concurrently, for large data & hot reloadable.
Mnemonics is analogous to Ruby's ActiveHash in it's usecase.
Add mnemonics to your list of dependencies in mix.exs.
def deps do
[
{:mnemonics, "~> 0.5"}
]
endStart under your application.
defmodule Your.Application do
use Application
def start(_type, _args) do
children = [
{Mnemonics, [name: Your.Mnemonics, ets_dir: "/tmp"]}
]
opts = [strategy: :one_for_one, name: Your.Supervisor]
Supervisor.start_link(children, opts)
end
endCreate an example.ets by :ets.tab2file/3. Then put it into the ets_dir. The examples.ets stores {:example1, %{id: :example1}}.
priv/
└repo/
└seeds/
└examples.ets
Create an Example module, use Mnemonics & load.
defmodule Example do
use Mnemonics, table_name: :examples, sup_name: Your.Mnemonics
end
Example.load(1)We can lookup the table.
:ets.lookup(Example.table_name(1), :example1)Let's reload a new table. Put a new examples.ets into the ets_dir & load it with a new version number.
Example.load(2)We can lookup the new table.
:ets.lookup(Example.table_name(2), :example1)
snap = Mnemonics.Snap.snap(Mnemonics.Snap.new(), 2, %{})
:ets.lookup(Example.table_name(snap), :example1)Mnemonics has cache function named Mnemonics.Snap.
snap = Mnemonics.Snap.snap(Mnemonics.Snap.new(), 2, %{})
get_and_update_in(snap[:examples].cache[:example1], fn
nil ->
example = :ets.lookup Example.table_name(snap), :example1
{example, example}
example ->
{example, example}
end)- Should
:publicor:protected.:protected(default) is recommended. - Can't
:named_table. {:read_concurrency, true}is recommended.
