Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose function to clear marina_cache using the RequestId #56

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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