Cache distroed
Kozlov-V opened this issue · 1 comments
Hello!
Please tell me this is normal behavior of a cache, then that for any wrong address, he destroyed?
23> {ok, _} = cache:start_link(my_cache, [{n, 10}, {ttl, 600}]).
{ok,<0.79.0>}
25> Val11 = cache:get(my_cache, <<"my key">>).
undefined
26> cache:i(my_cache).
[{heap,[90132]},
{expire,[1384955909]},
{size,[0]},
{memory,[307]}]
27> cache:i(my_cache1).
** exception exit: {noproc,{gen_server,call,[my_cache1,i]}}
in function gen_server:call/2 (gen_server.erl, line 180)
28> cache:i(my_cache).
** exception exit: {noproc,{gen_server,call,[my_cache,i]}}
in function gen_server:call/2 (gen_server.erl, line 180)
29> Val11 = cache:get(my_cache, <<"my key">>).
** exception exit: {noproc,
{gen_server,call,[my_cache,{get,<<"my key">>},60000]}}
in function gen_server:call/3 (gen_server.erl, line 188)
30> {ok, _} = cache:start_link(my_cache, [{n, 10}, {ttl, 600}]).
{ok,<0.90.0>}
31> {ok, _} = cache:start_link(my_cache, [{n, 10}, {ttl, 600}]).
** exception error: no match of right hand side value
{error,{already_started,<0.90.0>}}
32> Val11 = cache:get(my_cache, <<"my key">>).
** exception exit: {noproc,
{gen_server,call,[my_cache,{get,<<"my key">>},60000]}}
in function gen_server:call/3 (gen_server.erl, line 188)
33> cache:i(my_cache).
** exception exit: {noproc,{gen_server,call,[my_cache,i]}}
in function gen_server:call/2 (gen_server.erl, line 180)
Hello,
This is expected behaviour according to Erlang principles let-it-crash.
%% creates a cache process and links it to shell process
23> {ok, _} = cache:start_link(my_cache, [{n, 10}, {ttl, 600}]).
...
%% cause and exception (my_cache1) is not define. At this point shell process is crashed and ALL LINKED processes are crashed too. => my_cache process is dead as well.
27> cache:i(my_cache1).
** exception exit: {noproc,{gen_server,call,[my_cache1,i]}}
in function gen_server:call/2 (gen_server.erl, line 180)
%% new instance of cache process is successfully started
30> {ok, _} = cache:start_link(my_cache, [{n, 10}, {ttl, 600}]).
%% you are trying to start start a second cache instance with same name. Therefore you get an error {error,{already_started,<0.90.0>}}
%% this error terminates shell again...
31> {ok, _} = cache:start_link(my_cache, [{n, 10}, {ttl, 600}]).
** exception error: no match of right hand side value
{error,{already_started,<0.90.0>}}
In real application you will start a cache instance via app.config/sys.config file or as part of your application supervisor tree. The reported issue exists only inside interactive shell.