Module: CacheBack::WriteMixin::InstanceMethods
- Defined in:
- lib/cache_back/write_mixin.rb
Instance Method Summary collapse
- #cache_back_key ⇒ Object
- #cache_back_keys ⇒ Object
- #clear_cache_back_indices ⇒ Object
- #clear_local_cache_back_indices ⇒ Object
- #reload_with_cache_back_clearing(*args) ⇒ Object
- #store_in_cache_back ⇒ Object
Instance Method Details
#cache_back_key ⇒ Object
17 18 19 |
# File 'lib/cache_back/write_mixin.rb', line 17 def cache_back_key @cache_back_key ||= new_record? ? nil : self.class.cache_back_key_for_id(id) end |
#cache_back_keys ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/cache_back/write_mixin.rb', line 27 def cache_back_keys new_attributes = attributes.symbolize_keys old_attributes = Hash[changes.map {|attribute, values| [attribute, values[0]]}].symbolize_keys old_attributes.reverse_merge!(new_attributes) keys = [] self.class.cache_back_indices.each do |index| old_key = self.class.cache_back_key_for(index.map { |attribute| [attribute, old_attributes[attribute]]}) new_key = self.class.cache_back_key_for(index.map { |attribute| [attribute, new_attributes[attribute]]}) [old_key, new_key].uniq.each do |key| keys << key keys << "#{key}/first" end end keys end |
#clear_cache_back_indices ⇒ Object
46 47 48 49 50 |
# File 'lib/cache_back/write_mixin.rb', line 46 def clear_cache_back_indices cache_back_keys.each do |key| CacheBack.cache.delete(key) end end |
#clear_local_cache_back_indices ⇒ Object
52 53 54 55 56 |
# File 'lib/cache_back/write_mixin.rb', line 52 def clear_local_cache_back_indices cache_back_keys.each do |key| CacheBack.cache.delete_local(key) end end |
#reload_with_cache_back_clearing(*args) ⇒ Object
58 59 60 61 |
# File 'lib/cache_back/write_mixin.rb', line 58 def reload_with_cache_back_clearing(*args) clear_local_cache_back_indices reload_without_cache_back_clearing(*args) end |