NebulexMnesiaAdapter

View Source

Nebulex adapter using Mnesia as storage

Installation

If available in Hex, the package can be installed by adding nebulex_mnesia_adapter to your list of dependencies in mix.exs:

def deps do
  [
    {:nebulex_mnesia_adapter, "~> 0.1.0"}
  ]
end

Add the table configuration GenServer on the application module lib/my_app/application.ex

children =
  [
    ...
    {Nebulex.Adapters.Mnesia.Table, nodes: [Node.self()]}
    ...
  ]

Supervisor.start_link(childre, opts)

It is recommended to set the mnesia directory for disc copies on config/config.exs

config :mnesia, dir: ~c"/path/to/my/db/folder"

If you are pushing this to an environment ensure the folder is created ahead of time, Mnesia will not create the folder for you

Finally configure your cache module with Nebulex

defmodule MyApp.Cache do
  use Nebulex.Cache,
    otp_app: :my_app,
    adapter: Nebulex.Adapters.Mnesia
end

The adapter will check for expired keys (where ttl has been reached) every minute by default, to change the frequency of this check you can add to your config file:

config :my_app, MyApp.Cache,
    ttl: 300_000

This will check every 5 minutes and delete the expired cache keys

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/nebulex_mnesia_adapter.