Skip to content

Commit

Permalink
Expose function to clear marina_cache using the RequestId
Browse files Browse the repository at this point in the history
  • Loading branch information
lpgauth committed Aug 26, 2024
1 parent 9680635 commit 7dc84a8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/marina_cache.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

-export([
erase/2,
erase_node/1,
get/2,
init/0,
put/3
Expand All @@ -20,6 +21,15 @@ erase(Pool, Key) ->
{error, not_found}
end.


-spec erase_node(term()) -> ok.

erase_node(RequestId) ->
{Node, _} = RequestId,
Pool = marina_utils:node_to_pool(Node),
ets:select_delete(?ETS_TABLE_CACHE, [{{{'$1', '$2'}, '_'}, [], [{'==', '$1', Pool}]}]),
ok.

-spec get(atom(), binary()) -> {ok, term()} | {error, not_found}.

get(Pool, Key) ->
Expand Down
11 changes: 10 additions & 1 deletion src/marina_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
authenticate/1,
connect/2,
frame_flags/0,
node_to_pool/1,
pack/1,
query/2,
query_opts/2,
sync_msg/2,
startup/1,
sync_msg/2,
timeout/2,
unpack/1,
use_keyspace/1
Expand Down Expand Up @@ -45,6 +46,14 @@ frame_flags() ->
_ -> 0
end.

-spec node_to_pool(atom()) -> atom().

node_to_pool(Node) ->
NodeSplit = binary:split(erlang:atom_to_binary(Node), <<"_">>, [global]),
PoolSplit = lists:sublist(NodeSplit, length(NodeSplit) - 1),
PoolBin = erlang:iolist_to_binary(lists:join(<<"_">>, PoolSplit)),
erlang:binary_to_atom(PoolBin).

-spec pack(binary() | iolist()) ->
{ok, binary()} | {error, term()}.

Expand Down

0 comments on commit 7dc84a8

Please sign in to comment.