Class: Rack::RequestCache::Cache
- Inherits:
-
Object
- Object
- Rack::RequestCache::Cache
- Defined in:
- lib/rack/request_cache/cache.rb
Instance Method Summary collapse
- #cache(key) ⇒ Object
- #clear! ⇒ Object
- #fetch(key) ⇒ Object
- #has_key?(key) ⇒ Boolean
-
#initialize ⇒ Cache
constructor
A new instance of Cache.
Constructor Details
#initialize ⇒ Cache
Returns a new instance of Cache.
4 5 6 |
# File 'lib/rack/request_cache/cache.rb', line 4 def initialize @cache = {} end |
Instance Method Details
#cache(key) ⇒ Object
8 9 10 11 12 |
# File 'lib/rack/request_cache/cache.rb', line 8 def cache key raise ArgumentError, 'no block given' unless block_given? return @cache[key] if @cache.has_key? key @cache[key] = yield.freeze end |
#clear! ⇒ Object
14 15 16 |
# File 'lib/rack/request_cache/cache.rb', line 14 def clear! @cache.clear end |
#fetch(key) ⇒ Object
18 19 20 |
# File 'lib/rack/request_cache/cache.rb', line 18 def fetch key @cache.fetch key end |
#has_key?(key) ⇒ Boolean
22 23 24 |
# File 'lib/rack/request_cache/cache.rb', line 22 def has_key? key @cache.has_key? key end |