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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2c6eada3f463107c0237acb6a9df95d25c923658
4
- data.tar.gz: d0a85901f32e68fa48e91792896ac0faaea5747e
3
+ metadata.gz: 1fcc04e3d12bf33c0268a418a46e4d255d8f9e38
4
+ data.tar.gz: bae67e7130cb5ce2dfd39086c5757e72acf53217
5
5
  SHA512:
6
- metadata.gz: 42f536651f9799b6edacb11176f1644e1ec9e58911e739ed908922e062d91fafa887c6a48fd5d7fed7dc1a6717f29c94af4d91dc88ba02cc033847e9090b39d1
7
- data.tar.gz: 4c10ee82e94ee1d0f5d0002b86d5e567433d1eb9afbfd220818cde2bbacc442629673b2c192d1112d1cf36a0577acc41ca1f8a655c6301375de624ad3be38434
6
+ metadata.gz: e4fbdcfbf10f665d85497e149f35b418e1f90c79db76e32d78221abdea6a4c66415e5117c64d65fc3c4be5dc6d956ab3b3102f2f39823958d5b415b67978057b
7
+ data.tar.gz: 5cc6776a9d1060785c3d58f306a53157f9994706799905ab445503e23c6a96bc60fde75c56f6d4f9e7f0d102a35a113c3adf0282a72182208bfcb591c116fb49
@@ -1,8 +1,6 @@
1
1
  AllCops:
2
2
  Exclude:
3
3
  - .git/**/*
4
- - tmp/**/*
5
- - suo.gemspec
6
4
 
7
5
  Lint/DuplicateMethods:
8
6
  Enabled: true
@@ -1,3 +1,7 @@
1
+ ## 1.5.5
2
+
3
+ - Add more detailed documentation/comments.
4
+
1
5
  ## 1.5.4
2
6
 
3
7
  - Some minor wording updates.
@@ -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
- def self.caches
21
- @caches
22
- end
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
@@ -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
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module Caddy
3
- class TaskObserver
3
+ class TaskObserver #:nodoc:
4
4
  def initialize(error_handler, cache_name)
5
5
  @error_handler = error_handler || Caddy.error_handler
6
6
  @cache_name = cache_name
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Caddy
3
- VERSION = "1.5.4".freeze
3
+ VERSION = "1.5.5".freeze
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caddy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.4
4
+ version: 1.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Elser