When trying to work through the The Getting Started examples I am trying to do ETS as cache. However,
def init(table) do
# 3. We have replaced the names map by the ETS table
names = :ets.new(table, [:named_table, read_concurrency: true])
refs = %{}
{:ok, {names, refs}}
end
causes a compilation error
15:36:25.995 [notice] Application elixirtest exited: KV.start(:normal, []) returned an error: shutdown: failed to start child: KV.Registry
** (EXIT) an exception was raised:
** (ArgumentError) errors were found at the given arguments:
-
1st argument: not an atom
(stdlib 3.17) :ets.new({:ok, KV.Registry}, [:named_table, {:read_concurrency, true}]) (elixirtest 0.1.0) lib/kv/registry.ex:41: KV.Registry.init/1 (stdlib 3.17) gen_server.erl:423: :gen_server.init_it/2 (stdlib 3.17) gen_server.erl:390: :gen_server.init_it/6 (stdlib 3.17) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
** (Mix) Could not start application elixirtest: KV.start(:normal, []) returned an error: shutdown: failed to start child: KV.Registry
** (EXIT) an exception was raised:
** (ArgumentError) errors were found at the given arguments:
-
1st argument: not an atom
(stdlib 3.17) :ets.new({:ok, KV.Registry}, [:named_table, {:read_concurrency, true}]) (elixirtest 0.1.0) lib/kv/registry.ex:41: KV.Registry.init/1
I have tried a number of changes but none helps. What is wrong?