Module: Garner::Cache

Defined in:
lib/garner/cache.rb,
lib/garner/cache/binding.rb,
lib/garner/cache/context.rb,
lib/garner/cache/identity.rb

Defined Under Namespace

Modules: Binding, Context Classes: Identity

Class Method Summary collapse

Class Method Details

.fetch(bindings, key_hash, options_hash, &block) ⇒ Object

Fetch a result from cache.

Parameters:

  • bindings (Array)

    Objects to which the the cache result should be bound. These objects’ keys are injected into the compound cache key.

  • key_hash (Hash)

    Hash to comprise the compound cache key.

  • options_hash (Hash)

    Options to be passed to Garner.config.cache.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/garner/cache.rb', line 10

def self.fetch(bindings, key_hash, options_hash, &block)
  if (compound_key = compound_key(bindings, key_hash))
    result = Garner.config.cache.fetch(compound_key, options_hash) do
      yield
    end
    Garner.config.cache.delete(compound_key) unless result
  else
    result = yield
  end
  result
end