Class: Rack::App::FrontEnd::Template::Cache
- Inherits:
-
Object
- Object
- Rack::App::FrontEnd::Template::Cache
- Defined in:
- lib/rack/app/front_end/template/cache.rb
Instance Method Summary collapse
-
#clear ⇒ Object
Clears the cache.
-
#fetch(*key) { ... } ⇒ Object
Caches a value for key, or returns the previously cached value.
-
#initialize ⇒ Cache
constructor
A new instance of Cache.
Constructor Details
#initialize ⇒ Cache
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
#clear ⇒ Object
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.
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 |