Module: PreheatableCache
- Defined in:
- lib/preheatable_cache.rb
Constant Summary collapse
- VERSION =
File.read( File.join(File.dirname(__FILE__),'..','VERSION') ).strip
- NULL =
'preheatable_cache:null'
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/preheatable_cache.rb', line 6 def self.included(base) base.class_eval do def read_with_preheatable_cache(key, =nil) if not @preheatable_cache return read_without_preheatable_cache(key, ) end locally_cached = @preheatable_cache[key] if locally_cached == NULL nil elsif locally_cached.nil? read_without_preheatable_cache(key, ) else # keep preheatable cached immutable locally_cached.duplicable? ? locally_cached.dup : locally_cached end end alias_method_chain :read, :preheatable_cache end end |
Instance Method Details
#clear_preheatable_cache ⇒ Object
38 39 40 |
# File 'lib/preheatable_cache.rb', line 38 def clear_preheatable_cache @preheatable_cache = nil end |
#preheat(keys) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/preheatable_cache.rb', line 28 def preheat(keys) @preheatable_cache ||= {} data = fetch_via_read_multi(keys) store_into_preheatable_cache data add_cache_clearing_callback data end |