Module: SecondLevelCache::Mixin::ClassMethods
- Defined in:
- lib/second_level_cache.rb
Instance Attribute Summary collapse
-
#second_level_cache_options ⇒ Object
readonly
Returns the value of attribute second_level_cache_options.
Instance Method Summary collapse
- #acts_as_cached(options = {}) ⇒ Object
- #cache_key_prefix ⇒ Object
- #cache_store ⇒ Object
- #cache_version ⇒ Object
- #expire_second_level_cache(id) ⇒ Object
- #logger ⇒ Object
- #read_second_level_cache(id) ⇒ Object
- #second_level_cache_enabled? ⇒ Boolean
- #second_level_cache_key(id) ⇒ Object
- #without_second_level_cache ⇒ Object
Instance Attribute Details
#second_level_cache_options ⇒ Object (readonly)
Returns the value of attribute second_level_cache_options.
19 20 21 |
# File 'lib/second_level_cache.rb', line 19 def end |
Instance Method Details
#acts_as_cached(options = {}) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/second_level_cache.rb', line 21 def acts_as_cached( = {}) @second_level_cache_enabled = true = [:expires_in] ||= 1.week [:version] ||= 0 relation.class.send :include, SecondLevelCache::ActiveRecord::FinderMethods end |
#cache_key_prefix ⇒ Object
49 50 51 |
# File 'lib/second_level_cache.rb', line 49 def cache_key_prefix Config.cache_key_prefix end |
#cache_store ⇒ Object
41 42 43 |
# File 'lib/second_level_cache.rb', line 41 def cache_store Config.cache_store end |
#cache_version ⇒ Object
53 54 55 |
# File 'lib/second_level_cache.rb', line 53 def cache_version [:version] end |
#expire_second_level_cache(id) ⇒ Object
65 66 67 |
# File 'lib/second_level_cache.rb', line 65 def expire_second_level_cache(id) SecondLevelCache.cache_store.delete(second_level_cache_key(id)) if self.second_level_cache_enabled? end |
#logger ⇒ Object
45 46 47 |
# File 'lib/second_level_cache.rb', line 45 def logger Config.logger end |
#read_second_level_cache(id) ⇒ Object
61 62 63 |
# File 'lib/second_level_cache.rb', line 61 def read_second_level_cache(id) RecordMarshal.load(SecondLevelCache.cache_store.read(second_level_cache_key(id))) if self.second_level_cache_enabled? end |
#second_level_cache_enabled? ⇒ Boolean
29 30 31 |
# File 'lib/second_level_cache.rb', line 29 def second_level_cache_enabled? !!@second_level_cache_enabled end |
#second_level_cache_key(id) ⇒ Object
57 58 59 |
# File 'lib/second_level_cache.rb', line 57 def second_level_cache_key(id) "#{cache_key_prefix}/#{name.downcase}/#{id}/#{cache_version}" end |
#without_second_level_cache ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/second_level_cache.rb', line 33 def without_second_level_cache old, @second_level_cache_enabled = @second_level_cache_enabled, false yield if block_given? ensure @second_level_cache_enabled = old end |