fix cache model
This commit is contained in:
parent
b717de1069
commit
83afafcb12
@ -23,7 +23,6 @@
|
||||
%% 数据缓存
|
||||
-record(cache, {
|
||||
id = 0 :: integer(),
|
||||
method :: integer(),
|
||||
data :: binary()
|
||||
}).
|
||||
|
||||
|
||||
@ -194,8 +194,8 @@ handle_event(info, {auth_reply, Reply}, ?STATE_AUTH, State = #state{transport_pi
|
||||
%% 将缓存中的数据推送到服务器端
|
||||
handle_event(info, flush_cache, ?STATE_ACTIVATED, State = #state{transport_pid = TransportPid}) ->
|
||||
case cache_model:fetch_next() of
|
||||
{ok, #cache{id = Id, method = Method, data = Packet}} ->
|
||||
efka_transport:send(TransportPid, Method, Packet),
|
||||
{ok, #cache{id = Id, data = Packet}} ->
|
||||
efka_transport:send(TransportPid, Packet),
|
||||
cache_model:delete(Id),
|
||||
{keep_state, State, [{next_event, info, flush_cache}]};
|
||||
error ->
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
|
||||
%% API
|
||||
-export([start_link/0]).
|
||||
-export([insert/2, fetch_next/0, delete/1, get_all_cache/0]).
|
||||
-export([insert/1, fetch_next/0, delete/1, get_all_cache/0]).
|
||||
|
||||
%% gen_server callbacks
|
||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
|
||||
@ -30,9 +30,9 @@
|
||||
%%% API
|
||||
%%%===================================================================
|
||||
|
||||
-spec insert(Method :: integer(), Data :: binary()) -> ok | {error, Reason :: any()}.
|
||||
insert(Method, Data) when is_integer(Method), is_binary(Data) ->
|
||||
Cache = #cache{id = generate_id(), method = Method, data = Data},
|
||||
-spec insert(Data :: binary()) -> ok | {error, Reason :: any()}.
|
||||
insert(Data) when is_binary(Data) ->
|
||||
Cache = #cache{id = generate_id(), data = Data},
|
||||
gen_server:call(?SERVER, {insert, Cache}).
|
||||
|
||||
fetch_next() ->
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user