Class: TableChecksum::PerRequestCache
- Inherits:
-
Object
- Object
- TableChecksum::PerRequestCache
- Defined in:
- lib/table_checksum/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.
23 24 25 |
# File 'lib/table_checksum/per_request_cache.rb', line 23 def initialize(app) @app = app end |
Class Method Details
.cache_key ⇒ Object
9 10 11 |
# File 'lib/table_checksum/per_request_cache.rb', line 9 def cache_key "#{Process.pid}_#{Thread.current.object_id}".to_sym end |
.clear_the_cache ⇒ Object
13 14 15 |
# File 'lib/table_checksum/per_request_cache.rb', line 13 def clear_the_cache @cache.delete(self.cache_key) end |
.fetch(key, &block) ⇒ Object
17 18 19 20 |
# File 'lib/table_checksum/per_request_cache.rb', line 17 def fetch(key, &block) return yield if @cache.nil? @cache[self.cache_key][key] ||= yield end |
.open_the_cache ⇒ Object
4 5 6 7 |
# File 'lib/table_checksum/per_request_cache.rb', line 4 def open_the_cache @cache ||= {} @cache[self.cache_key] ||= {} end |
Instance Method Details
#call(env) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/table_checksum/per_request_cache.rb', line 27 def call(env) self.class.open_the_cache @app.call(env) ensure self.class.clear_the_cache end |