Class: Rack::App::FrontEnd::Template::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/app/front_end/template/cache.rb

Instance Method Summary collapse

Constructor Details

#initializeCache

Returns a new instance of Cache.



2
3
4
# File 'lib/rack/app/front_end/template/cache.rb', line 2

def initialize
  @cache = {}
end

Instance Method Details

#clearObject

Clears the cache.



19
20
21
# File 'lib/rack/app/front_end/template/cache.rb', line 19

def clear
  @cache = {}
end

#fetch(*key) { ... } ⇒ Object

Caches a value for key, or returns the previously cached value. If a value has been previously cached for key then it is returned. Otherwise, block is yielded to and its return value which may be nil, is cached under key and returned.

Yields:

Yield Returns:

  • the value to cache for key



12
13
14
15
16
# File 'lib/rack/app/front_end/template/cache.rb', line 12

def fetch(*key)
  @cache.fetch(key) do
    @cache[key] = yield
  end
end