Skip to content

Commit

Permalink
Merge pull request #56 from lpgauth/feature/delete-cache
Browse files Browse the repository at this point in the history
Expose function to clear marina_cache using the RequestId
  • Loading branch information
lpgauth authored Aug 26, 2024
2 parents 9680635 + bae8540 commit 9b467b3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
9 changes: 9 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_server/1,
get/2,
init/0,
put/3
Expand All @@ -20,6 +21,14 @@ erase(Pool, Key) ->
{error, not_found}
end.


-spec erase_server(shackle:request_id()) -> ok.

erase_server({ServerName, _}) ->
Pool = marina_utils:server_to_pool(ServerName),
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 @@ -8,8 +8,9 @@
pack/1,
query/2,
query_opts/2,
sync_msg/2,
server_to_pool/1,
startup/1,
sync_msg/2,
timeout/2,
unpack/1,
use_keyspace/1
Expand Down Expand Up @@ -88,6 +89,14 @@ query_opts(timeout, QueryOpts) ->
query_opts(values, QueryOpts) ->
maps:get(values, QueryOpts, undefined).

-spec server_to_pool(atom()) -> atom().

server_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 sync_msg(inet:socket(), iodata()) ->
{ok, term()} | {error, term()}.

Expand Down

0 comments on commit 9b467b3

Please sign in to comment.