Module: ActiveRecordCache
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/active_record_cache.rb,
lib/active_record_cache/record_cache.rb,
lib/active_record_cache/defaults_handler.rb,
lib/active_record_cache/relation_extension.rb
Defined Under Namespace
Modules: ClassMethods, RelationExtension Classes: DefaultsHandler, RecordCache
Class Method Summary collapse
-
.cache ⇒ Object
Get the default cache used by models.
-
.cache=(value) ⇒ Object
Set the default cache used by models.
-
.enable_by_default_on(options) ⇒ Object
Set the default for classes if they should use the cache or not for the duration of a block.
Instance Method Summary collapse
-
#expire_cache_entry ⇒ Object
Expire the record out of the cache.
Class Method Details
.cache ⇒ Object
Get the default cache used by models. Defaults to Rails.cache.
24 25 26 27 28 29 |
# File 'lib/active_record_cache.rb', line 24 def cache unless defined?(@cache) @cache = Rails.cache if defined?(Rails.cache) end @cache end |
.cache=(value) ⇒ Object
Set the default cache used by models.
32 33 34 |
# File 'lib/active_record_cache.rb', line 32 def cache=(value) @cache = value end |
.enable_by_default_on(options) ⇒ Object
Set the default for classes if they should use the cache or not for the duration of a block. The options hash should be a hash of => (true|false).
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/active_record_cache.rb', line 38 def enable_by_default_on() current_defaults = Thread.current[:active_record_cache_defaults] begin defaults = current_defaults ? current_defaults.dup : {} Thread.current[:active_record_cache_defaults] = defaults .each do |klass, default| defaults[klass.is_a?(Class) ? klass.name : klass.to_s] = !!default end yield ensure Thread.current[:active_record_cache_defaults] = current_defaults end end |
Instance Method Details
#expire_cache_entry ⇒ Object
Expire the record out of the cache.
54 55 56 |
# File 'lib/active_record_cache.rb', line 54 def expire_cache_entry self.class.expire_cache_entry(id) end |