Class: Rack::PerRequestCache
- Inherits:
-
Object
- Object
- Rack::PerRequestCache
- Defined in:
- lib/rack/per_request_cache.rb
Class Method Summary collapse
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ PerRequestCache
constructor
A new instance of PerRequestCache.
Constructor Details
#initialize(app) ⇒ PerRequestCache
Returns a new instance of PerRequestCache.
4 5 6 |
# File 'lib/rack/per_request_cache.rb', line 4 def initialize(app) @app = app end |
Class Method Details
.cached(key, &block) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/rack/per_request_cache.rb', line 25 def cached(key, &block) return yield if @cache.nil? return @cache[key] if @cache.has_key?(key) @cache[key] = yield end |
.clear_cache ⇒ Object
21 22 23 |
# File 'lib/rack/per_request_cache.rb', line 21 def clear_cache @cache = nil end |
.initialize_cache ⇒ Object
17 18 19 |
# File 'lib/rack/per_request_cache.rb', line 17 def initialize_cache @cache = {} end |
Instance Method Details
#call(env) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/rack/per_request_cache.rb', line 8 def call(env) self.class.initialize_cache @app.call env ensure self.class.clear_cache end |