Class: Babushka::DepCache

Inherits:
Object show all
Defined in:
lib/babushka/dep_cache.rb

Instance Method Summary collapse

Constructor Details

#initializeDepCache

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