@@ -7,7 +7,7 @@ defmodule Cachex.Warmer do
7
7
Doing this allows for easy pulling against expensive values (such as those from
8
8
a backing database or remote server), without risking heavy usage.
9
9
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
11
11
will not complete booting up, until your cache has been warmed. This guarantees
12
12
that there will not be any time where the application is available, without the
13
13
desired data in the cache.
@@ -68,10 +68,8 @@ defmodule Cachex.Warmer do
68
68
#
69
69
# Initialization will trigger an initial cache warming, and store
70
70
# 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 }
75
73
76
74
@ doc false
77
75
# Warms a number of keys in a cache.
@@ -81,14 +79,7 @@ defmodule Cachex.Warmer do
81
79
# cache via `Cachex.put_many/3` if returns in a Tuple tagged with the
82
80
# `:ok` atom. If `:ignore` is returned, nothing happens aside from
83
81
# 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
92
83
# execute, passing state
93
84
case execute ( state ) do
94
85
# no changes
@@ -106,6 +97,9 @@ defmodule Cachex.Warmer do
106
97
107
98
# trigger the warming to happen again after the interval
108
99
:erlang . send_after ( interval ( ) , self ( ) , :cachex_warmer )
100
+
101
+ # no reply, and the state persist
102
+ { :noreply , process_state }
109
103
end
110
104
end
111
105
end
0 commit comments