Skip to content

Commit 5699a43

Browse files
committed
Minor tweaks to warmer startup
1 parent 9fdbe79 commit 5699a43

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

lib/cachex/warmer.ex

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ defmodule Cachex.Warmer do
77
Doing this allows for easy pulling against expensive values (such as those from
88
a backing database or remote server), without risking heavy usage.
99
10-
Warmers will block when the cache is started to ensure that the application
10+
Warmers will block when the cache is started to ensure that the application
1111
will not complete booting up, until your cache has been warmed. This guarantees
1212
that there will not be any time where the application is available, without the
1313
desired data in the cache.
@@ -68,10 +68,8 @@ defmodule Cachex.Warmer do
6868
#
6969
# Initialization will trigger an initial cache warming, and store
7070
# the provided state for later to provide during further warming.
71-
def init(state) do
72-
do_execute(state)
73-
{ :ok, state }
74-
end
71+
def init(state),
72+
do: { handle_info(:cachex_warmer, state) && :ok, state }
7573

7674
@doc false
7775
# Warms a number of keys in a cache.
@@ -81,14 +79,7 @@ defmodule Cachex.Warmer do
8179
# cache via `Cachex.put_many/3` if returns in a Tuple tagged with the
8280
# `:ok` atom. If `:ignore` is returned, nothing happens aside from
8381
# scheduling the next execution of the warming to occur on interval.
84-
def handle_info(:cachex_warmer, process_state) do
85-
do_execute(process_state)
86-
87-
# no reply, and the state persist
88-
{ :noreply, process_state }
89-
end
90-
91-
defp do_execute({ cache, state } = process_state) do
82+
def handle_info(:cachex_warmer, { cache, state } = process_state) do
9283
# execute, passing state
9384
case execute(state) do
9485
# no changes
@@ -106,6 +97,9 @@ defmodule Cachex.Warmer do
10697

10798
# trigger the warming to happen again after the interval
10899
:erlang.send_after(interval(), self(), :cachex_warmer)
100+
101+
# no reply, and the state persist
102+
{ :noreply, process_state }
109103
end
110104
end
111105
end

0 commit comments

Comments
 (0)