Use gen_server instead of gen_server2 for caches

This commit is contained in:
Daniil Fedotov 2018-01-31 11:44:15 +00:00
parent 13e35274bb
commit 0fdfa0fbab
4 changed files with 18 additions and 18 deletions

View File

@ -15,7 +15,7 @@
%%
-module(rabbit_auth_cache_dict).
-behaviour(gen_server2).
-behaviour(gen_server).
-compile({no_auto_import,[get/1]}).
-compile({no_auto_import,[put/2]}).
@ -27,11 +27,11 @@
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).
start_link() -> gen_server2:start_link({local, ?MODULE}, ?MODULE, [], []).
start_link() -> gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
get(Key) -> gen_server2:call(?MODULE, {get, Key}).
put(Key, Value, TTL) -> gen_server2:cast(?MODULE, {put, Key, Value, TTL}).
delete(Key) -> gen_server2:call(?MODULE, {delete, Key}).
get(Key) -> gen_server:call(?MODULE, {get, Key}).
put(Key, Value, TTL) -> gen_server:cast(?MODULE, {put, Key, Value, TTL}).
delete(Key) -> gen_server:call(?MODULE, {delete, Key}).
init(_Args) -> {ok, nostate}.
@ -66,5 +66,5 @@ do_delete(Key) ->
undefined -> ok;
Tref -> timer:cancel(Tref),
erase({timers, Key})
end.

View File

@ -15,7 +15,7 @@
%%
-module(rabbit_auth_cache_ets).
-behaviour(gen_server2).
-behaviour(gen_server).
-compile({no_auto_import,[get/1]}).
-compile({no_auto_import,[put/2]}).
@ -29,13 +29,13 @@
-record(state, {cache, timers, ttl}).
start_link() -> gen_server2:start_link({local, ?MODULE}, ?MODULE, [], []).
start_link() -> gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
get(Key) -> gen_server2:call(?MODULE, {get, Key}).
get(Key) -> gen_server:call(?MODULE, {get, Key}).
put(Key, Value, TTL) ->
Expiration = rabbit_auth_cache:expiration(TTL),
gen_server2:cast(?MODULE, {put, Key, Value, TTL, Expiration}).
delete(Key) -> gen_server2:call(?MODULE, {delete, Key}).
gen_server:cast(?MODULE, {put, Key, Value, TTL, Expiration}).
delete(Key) -> gen_server:call(?MODULE, {delete, Key}).
init(_Args) ->
{ok, #state{cache = ets:new(?MODULE, [set, private]),

View File

@ -31,7 +31,7 @@
segment_size}).
start_link(SegmentSize) ->
gen_server2:start_link({local, ?MODULE}, ?MODULE, [SegmentSize], []).
gen_server:start_link({local, ?MODULE}, ?MODULE, [SegmentSize], []).
get(Key) ->
case get_from_segments(Key) of
@ -41,13 +41,13 @@ get(Key) ->
put(Key, Value, TTL) ->
Expiration = rabbit_auth_cache:expiration(TTL),
Segment = gen_server2:call(?MODULE, {get_write_segment, Expiration}),
Segment = gen_server:call(?MODULE, {get_write_segment, Expiration}),
ets:insert(Segment, {Key, {Expiration, Value}}),
ok.
delete(Key) ->
[ets:delete(Table, Key)
|| Table <- gen_server2:call(?MODULE, get_segment_tables)].
|| Table <- gen_server:call(?MODULE, get_segment_tables)].
gc() ->
case whereis(?MODULE) of
@ -105,7 +105,7 @@ maybe_add_segment(Expiration, SegmentSize, OldSegments) ->
end.
get_from_segments(Key) ->
Tables = gen_server2:call(?MODULE, get_segment_tables),
Tables = gen_server:call(?MODULE, get_segment_tables),
lists:flatmap(
fun(undefined) -> [];
(T) ->

View File

@ -15,7 +15,7 @@
%%
-module(rabbit_auth_cache_ets_segmented_stateless).
-behaviour(gen_server2).
-behaviour(gen_server).
-behaviour(rabbit_auth_cache).
-export([start_link/1,
@ -30,7 +30,7 @@
-record(state, {gc_timer}).
start_link(SegmentSize) ->
gen_server2:start_link({local, ?MODULE}, ?MODULE, [SegmentSize], []).
gen_server:start_link({local, ?MODULE}, ?MODULE, [SegmentSize], []).
get(Key) ->
case get_from_segments(Key) of
@ -99,7 +99,7 @@ segment(Expiration, SegmentSize) ->
End.
add_segment(Segment) ->
gen_server2:call(?MODULE, {add_segment, Segment}).
gen_server:call(?MODULE, {add_segment, Segment}).
do_add_segment(Segment) ->
case ets:lookup(?SEGMENT_TABLE, Segment) of