Class: Babushka::DepCache
Instance Method Summary collapse
-
#initialize ⇒ DepCache
constructor
A new instance of DepCache.
- #read(key, opts = {}, &block) ⇒ Object
Constructor Details
#initialize ⇒ DepCache
Returns a new instance of DepCache.
4 5 6 |
# File 'lib/babushka/dep_cache.rb', line 4 def initialize @caches = {} end |
Instance Method Details
#read(key, opts = {}, &block) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/babushka/dep_cache.rb', line 8 def read key, opts = {}, &block if @caches.has_key?(key) @caches[key].tap {|value| opts[:hit].call(value) if opts.has_key?(:hit) } else @caches[key] = block.call end end |