lib/caddy.rb in caddy-1.0.0 vs lib/caddy.rb in caddy-1.0.1

- old
+ new

@@ -12,20 +12,21 @@ REFRESH_INTERVAL_JITTER_PCT = 0.15 @task = nil @refresh_interval = DEFAULT_REFRESH_INTERVAL @_started_pid = nil + @_cache = nil def self.[](k) cache[k] end def self.cache raise "Please run `Caddy.start` before attempting to access the cache" unless @task - raise "Caddy cache access before initial load; allow some more time for your app to start up" unless @task.value + raise "Caddy cache access before initial load; allow some more time for your app to start up" unless @_cache - @task.value + @_cache end def self.start unless refresher && refresher.respond_to?(:call) raise "Please set your cache refresher via `Caddy.refresher = -> { <code that returns a value> }`" @@ -45,10 +46,17 @@ @task = Concurrent::TimerTask.new( run_now: true, execution_interval: interval, timeout_interval: timeout_interval - ) { refresher.call } + ) do + begin + @_cache = refresher.call + @_cache.freeze if @_cache.respond_to?(:freeze) + rescue + raise + end + end @task.add_observer(Caddy::TaskObserver.new) @task.execute @_started_pid = $$