fix cache model

This commit is contained in:
anlicheng 2025-09-18 10:59:24 +08:00
parent b717de1069
commit 83afafcb12
3 changed files with 6 additions and 7 deletions

View File

@ -23,7 +23,6 @@
%% %%
-record(cache, { -record(cache, {
id = 0 :: integer(), id = 0 :: integer(),
method :: integer(),
data :: binary() data :: binary()
}). }).

View File

@ -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}) -> handle_event(info, flush_cache, ?STATE_ACTIVATED, State = #state{transport_pid = TransportPid}) ->
case cache_model:fetch_next() of case cache_model:fetch_next() of
{ok, #cache{id = Id, method = Method, data = Packet}} -> {ok, #cache{id = Id, data = Packet}} ->
efka_transport:send(TransportPid, Method, Packet), efka_transport:send(TransportPid, Packet),
cache_model:delete(Id), cache_model:delete(Id),
{keep_state, State, [{next_event, info, flush_cache}]}; {keep_state, State, [{next_event, info, flush_cache}]};
error -> error ->

View File

@ -14,7 +14,7 @@
%% API %% API
-export([start_link/0]). -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 %% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
@ -30,9 +30,9 @@
%%% API %%% API
%%%=================================================================== %%%===================================================================
-spec insert(Method :: integer(), Data :: binary()) -> ok | {error, Reason :: any()}. -spec insert(Data :: binary()) -> ok | {error, Reason :: any()}.
insert(Method, Data) when is_integer(Method), is_binary(Data) -> insert(Data) when is_binary(Data) ->
Cache = #cache{id = generate_id(), method = Method, data = Data}, Cache = #cache{id = generate_id(), data = Data},
gen_server:call(?SERVER, {insert, Cache}). gen_server:call(?SERVER, {insert, Cache}).
fetch_next() -> fetch_next() ->