caddy 1.5.4 → 1.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +0 -2
- data/CHANGELOG.md +4 -0
- data/lib/caddy.rb +16 -4
- data/lib/caddy/cache.rb +20 -0
- data/lib/caddy/task_observer.rb +1 -1
- data/lib/caddy/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1fcc04e3d12bf33c0268a418a46e4d255d8f9e38
|
4
|
+
data.tar.gz: bae67e7130cb5ce2dfd39086c5757e72acf53217
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4fbdcfbf10f665d85497e149f35b418e1f90c79db76e32d78221abdea6a4c66415e5117c64d65fc3c4be5dc6d956ab3b3102f2f39823958d5b415b67978057b
|
7
|
+
data.tar.gz: 5cc6776a9d1060785c3d58f306a53157f9994706799905ab445503e23c6a96bc60fde75c56f6d4f9e7f0d102a35a113c3adf0282a72182208bfcb591c116fb49
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/lib/caddy.rb
CHANGED
@@ -13,14 +13,22 @@ module Caddy
|
|
13
13
|
@started_pid = nil
|
14
14
|
@caches = Hash.new { |h, k| h[k] = Caddy::Cache.new(k) }
|
15
15
|
|
16
|
+
##
|
17
|
+
# Returns the cache object for key +k+.
|
18
|
+
#
|
19
|
+
# If the cache at +k+ does not exist yet, Caddy will initialize an empty one.
|
16
20
|
def self.[](k)
|
17
21
|
@caches[k]
|
18
22
|
end
|
19
23
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
+
##
|
25
|
+
# Starts the Caddy refresh processes for all caches.
|
26
|
+
#
|
27
|
+
# If the refresh process was started pre-fork, Caddy will error out, as this means
|
28
|
+
# the refresh process would have been killed by the fork.
|
29
|
+
#
|
30
|
+
# Caddy freezes the hash of caches at this point, so no more further caches can be
|
31
|
+
# added after start.
|
24
32
|
def self.start
|
25
33
|
if !@started_pid
|
26
34
|
@started_pid = $$
|
@@ -33,10 +41,14 @@ module Caddy
|
|
33
41
|
@caches.values.each(&:start).all?
|
34
42
|
end
|
35
43
|
|
44
|
+
##
|
45
|
+
# Cleanly shut down all currently running refreshers.
|
36
46
|
def self.stop
|
37
47
|
@caches.values.each(&:stop).all?
|
38
48
|
end
|
39
49
|
|
50
|
+
##
|
51
|
+
# Start and then stop again all refreshers. Useful for triggering an immediate refresh of all caches.
|
40
52
|
def self.restart
|
41
53
|
stop
|
42
54
|
start
|
data/lib/caddy/cache.rb
CHANGED
@@ -6,6 +6,8 @@ module Caddy
|
|
6
6
|
|
7
7
|
attr_accessor :refresher, :refresh_interval, :error_handler
|
8
8
|
|
9
|
+
##
|
10
|
+
# Create a new cache with key +key+.
|
9
11
|
def initialize(key)
|
10
12
|
@task = nil
|
11
13
|
@refresh_interval = DEFAULT_REFRESH_INTERVAL
|
@@ -13,10 +15,17 @@ module Caddy
|
|
13
15
|
@key = key
|
14
16
|
end
|
15
17
|
|
18
|
+
##
|
19
|
+
# Convenience method for getting the value of the refresher-returned object at path +k+,
|
20
|
+
# assuming the refresher-returned value responds to <tt>[]</tt>.
|
21
|
+
#
|
22
|
+
# If not, #cache can be used instead to access the refresher-returned object.
|
16
23
|
def [](k)
|
17
24
|
cache[k]
|
18
25
|
end
|
19
26
|
|
27
|
+
##
|
28
|
+
# Returns the refresher-produced value that is used as the cache.
|
20
29
|
def cache
|
21
30
|
raise "Please run `Caddy.start` before attempting to access the cache" unless @task && @task.running?
|
22
31
|
raise "Caddy cache access of :#{@key} before initial load; allow some more time for your app to start up" unless @cache
|
@@ -24,6 +33,13 @@ module Caddy
|
|
24
33
|
@cache
|
25
34
|
end
|
26
35
|
|
36
|
+
##
|
37
|
+
# Starts the period refresh cycle.
|
38
|
+
#
|
39
|
+
# Every +refresh_interval+ seconds -- smoothed by a jitter amount (a random amount +/- +REFRESH_INTERVAL_JITTER_PCT+) --
|
40
|
+
# the refresher lambda is called and the results stored in +cache+.
|
41
|
+
#
|
42
|
+
# Note that the result of the refresh is frozen to avoid multithreading mutations.
|
27
43
|
def start
|
28
44
|
unless refresher && refresher.respond_to?(:call)
|
29
45
|
raise "Please set your cache refresher via `Caddy[:#{@key}].refresher = -> { <code that returns a value> }`"
|
@@ -52,6 +68,10 @@ module Caddy
|
|
52
68
|
@task.running?
|
53
69
|
end
|
54
70
|
|
71
|
+
##
|
72
|
+
# Stops the current executing refresher.
|
73
|
+
#
|
74
|
+
# The current cache value is persisted even if the task is stopped.
|
55
75
|
def stop
|
56
76
|
@task.shutdown if @task && @task.running?
|
57
77
|
end
|
data/lib/caddy/task_observer.rb
CHANGED
data/lib/caddy/version.rb
CHANGED