Skip to content

Commit

Permalink
Improve types and compiler warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonVides committed Sep 17, 2024
1 parent dfa11fe commit ddb3f34
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
5 changes: 4 additions & 1 deletion rebar.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{erl_opts, []}.
{erl_opts,
[warn_missing_doc, warn_missing_spec, warn_unused_import,
warn_export_vars, verbose, report, debug_info
]}.

{deps, [
{telemetry, "1.3.0"}
Expand Down
1 change: 1 addition & 0 deletions src/segmented_cache_helpers.erl
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ compare_and_swap(Attempts, EtsSegment, Key, Value, MergerFun) ->
%% Note that we must first empty the last table, and then rotate the index. If it was done
%% in the opposite order, there's a chance a worker can insert an entry at the front just
%% before the table is purged.
-spec purge_last_segment_and_rotate(segmented_cache:name()) -> non_neg_integer().
purge_last_segment_and_rotate(Name) ->
SegmentRecord = get_cache_config(Name),
Index = atomics:get(SegmentRecord#segmented_cache.index, 1),
Expand Down
11 changes: 6 additions & 5 deletions src/segmented_cache_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2]).

-type request_content() :: term().

-record(cache_state, {scope :: segmented_cache:scope(),
name :: segmented_cache:name(),
ttl :: timeout(),
timer_ref :: undefined | reference()}).
-type state() :: #cache_state{}.

%%====================================================================
%% API
Expand All @@ -40,7 +40,7 @@ request_delete_pattern(Name, Pattern) ->
%% gen_server callbacks
%%====================================================================

-spec init({segmented_cache:name(), segmented_cache:opts()}) -> {ok, #cache_state{}}.
-spec init({segmented_cache:name(), segmented_cache:opts()}) -> {ok, state()}.
init({Name, Opts}) ->
#{scope := Scope, ttl := TTL} = segmented_cache_helpers:init_cache_config(Name, Opts),
pg:join(Scope, Name, self()),
Expand All @@ -52,11 +52,11 @@ init({Name, Opts}) ->
{ok, #cache_state{scope = Scope, name = Name, ttl = TTL, timer_ref = TimerRef}}
end.

-spec handle_call(any(), gen_server:from(), #cache_state{}) -> {reply, ok, #cache_state{}}.
-spec handle_call(any(), gen_server:from(), state()) -> {reply, ok, state()}.
handle_call(_Msg, _From, State) ->
{reply, ok, State}.

-spec handle_cast(term(), #cache_state{}) -> {noreply, #cache_state{}}.
-spec handle_cast(term(), state()) -> {noreply, state()}.
handle_cast({delete_entry, Key}, #cache_state{name = Name} = State) ->
segmented_cache_helpers:delete_entry(Name, Key),
{noreply, State};
Expand All @@ -66,7 +66,7 @@ handle_cast({delete_pattern, Pattern}, #cache_state{name = Name} = State) ->
handle_cast(_Msg, State) ->
{noreply, State}.

-spec handle_info(any(), #cache_state{}) -> {noreply, #cache_state{}}.
-spec handle_info(any(), state()) -> {noreply, state()}.
handle_info(purge, #cache_state{name = Name, ttl = TTL} = State) ->
segmented_cache_helpers:purge_last_segment_and_rotate(Name),
case TTL of
Expand All @@ -76,6 +76,7 @@ handle_info(purge, #cache_state{name = Name, ttl = TTL} = State) ->
handle_info(_Msg, State) ->
{noreply, State}.

-spec terminate(normal | shutdown | {shutdown, term()} | term(), state()) -> term().
terminate(_Reason, #cache_state{name = Name, timer_ref = TimerRef}) ->
segmented_cache_helpers:erase_cache_config(Name),
case TimerRef of
Expand Down

0 comments on commit ddb3f34

Please sign in to comment.