Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow additional :ets config to be passed in on start up #3

Merged
merged 1 commit into from
Jul 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/mentat.ex
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ defmodule Mentat do
Options:

`:name` - The name of the cache
`:ets_args` - Additional arguments to pass to `:ets.new/2`
`:cleanup_interval` - How often the janitor process will remove old keys (defaults to 5_000).
"""
def start_link(args) do
Expand Down Expand Up @@ -185,7 +186,8 @@ defmodule Mentat do
def init(args) do
name = Keyword.get(args, :name)
interval = Keyword.get(args, :cleanup_interval, 5_000)
^name = :ets.new(name, [:set, :named_table, :public])
ets_args = Keyword.get(args, :ets_args, [])
^name = :ets.new(name, [:set, :named_table, :public] ++ ets_args)

children = [
{Mentat.Janitor, [name: :"#{name}_janitor", interval: interval, cache: name]}
Expand Down
10 changes: 10 additions & 0 deletions test/mentat_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,14 @@ defmodule MentatTest do
assert Mentat.delete(cache, :key) == true
end
end

describe "configuration" do
test "additional :ets arguments can be passed via :ets_args" do
stop_supervised(Mentat)
name = ConcurrentCache
start_supervised({Mentat, name: name, ets_args: [read_concurrency: true]})
info = :ets.info(name)
assert Keyword.fetch!(info, :read_concurrency)
end
end
end