Class: Rack::RequestCache::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/request_cache/cache.rb

Instance Method Summary collapse

Constructor Details

#initializeCache

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

Raises:

  • (ArgumentError)


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

Returns:

  • (Boolean)


22
23
24
# File 'lib/rack/request_cache/cache.rb', line 22

def has_key? key
  @cache.has_key? key
end