lib/caddy.rb in caddy-1.5.4 vs lib/caddy.rb in caddy-1.5.5
- old
+ new
@@ -11,18 +11,26 @@
end
@started_pid = nil
@caches = Hash.new { |h, k| h[k] = Caddy::Cache.new(k) }
+ ##
+ # Returns the cache object for key +k+.
+ #
+ # If the cache at +k+ does not exist yet, Caddy will initialize an empty one.
def self.[](k)
@caches[k]
end
- def self.caches
- @caches
- end
-
+ ##
+ # Starts the Caddy refresh processes for all caches.
+ #
+ # If the refresh process was started pre-fork, Caddy will error out, as this means
+ # the refresh process would have been killed by the fork.
+ #
+ # Caddy freezes the hash of caches at this point, so no more further caches can be
+ # added after start.
def self.start
if !@started_pid
@started_pid = $$
elsif @started_pid && $$ != @started_pid
raise "Please run `Caddy.start` *after* forking, as the refresh thread will get killed after fork"
@@ -31,13 +39,17 @@
@caches.freeze
@caches.values.each(&:start).all?
end
+ ##
+ # Cleanly shut down all currently running refreshers.
def self.stop
@caches.values.each(&:stop).all?
end
+ ##
+ # Start and then stop again all refreshers. Useful for triggering an immediate refresh of all caches.
def self.restart
stop
start
end
end