Module: SecondLevelCache::Mixin
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/second_level_cache/mixin.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #expire_changed_association_uniq_keys ⇒ Object
- #expire_second_level_cache ⇒ Object
- #second_level_cache_key ⇒ Object
- #write_second_level_cache ⇒ Object (also: #update_second_level_cache)
Instance Method Details
#expire_changed_association_uniq_keys ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/second_level_cache/mixin.rb', line 83 def expire_changed_association_uniq_keys reflections = self.class.reflections.select { |_, reflection| reflection.belongs_to? } changed_keys = reflections.map { |_, reflection| reflection.foreign_key } & previous_changes.keys changed_keys.each do |key| SecondLevelCache.cache_store.delete(self.class.send(:cache_uniq_key, key => previous_changes[key][0])) end end |
#expire_second_level_cache ⇒ Object
68 69 70 71 |
# File 'lib/second_level_cache/mixin.rb', line 68 def expire_second_level_cache return unless self.class.second_level_cache_enabled? SecondLevelCache.cache_store.delete(second_level_cache_key) end |
#second_level_cache_key ⇒ Object
64 65 66 |
# File 'lib/second_level_cache/mixin.rb', line 64 def second_level_cache_key self.class.second_level_cache_key(id) end |
#write_second_level_cache ⇒ Object Also known as: update_second_level_cache
73 74 75 76 77 78 79 |
# File 'lib/second_level_cache/mixin.rb', line 73 def write_second_level_cache return unless self.class.second_level_cache_enabled? marshal = RecordMarshal.dump(self) expires_in = self.class.[:expires_in] expire_changed_association_uniq_keys SecondLevelCache.cache_store.write(second_level_cache_key, marshal, expires_in: expires_in) end |