Module: Cacheable::Expiry

Defined in:
lib/cacheable/expiry.rb

Instance Method Summary collapse

Instance Method Details

#expire_all_attribute_cacheObject



30
31
32
33
34
35
# File 'lib/cacheable/expiry.rb', line 30

def expire_all_attribute_cache
  self.class.cached_indices.each do |attribute, values|
    value = self.send(attribute)
    Rails.cache.delete self.class.all_attribute_cache_key(attribute, value)
  end
end

#expire_association_cache(name) ⇒ Object



51
52
53
# File 'lib/cacheable/expiry.rb', line 51

def expire_association_cache(name)
  Rails.cache.delete have_association_cache_key(name)
end

#expire_attribute_cacheObject



23
24
25
26
27
28
# File 'lib/cacheable/expiry.rb', line 23

def expire_attribute_cache
  self.class.cached_indices.each do |attribute, values|
    value = self.send(attribute)
    Rails.cache.delete self.class.attribute_cache_key(attribute, value)
  end
end

#expire_class_method_cacheObject



43
44
45
46
47
48
49
# File 'lib/cacheable/expiry.rb', line 43

def expire_class_method_cache
  self.class.cached_class_methods.each do |meth, args|
    args.each do |arg|
      Rails.cache.delete self.class.class_method_cache_key(meth, arg)
    end
  end
end

#expire_key_cacheObject



17
18
19
20
21
# File 'lib/cacheable/expiry.rb', line 17

def expire_key_cache
  model_cache_keys.each do |key|
    Rails.cache.delete key
  end
end

#expire_method_cacheObject



37
38
39
40
41
# File 'lib/cacheable/expiry.rb', line 37

def expire_method_cache
  self.class.cached_methods.each do |meth|
    Rails.cache.delete method_cache_key(meth)
  end
end

#expire_model_cacheObject



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/cacheable/expiry.rb', line 3

def expire_model_cache
  expire_key_cache            if self.class.cached_key
  expire_attribute_cache      if self.class.cached_indices.present?
  expire_all_attribute_cache  if self.class.cached_indices.present?
  expire_method_cache         if self.class.cached_methods.present?
  expire_class_method_cache   if self.class.cached_class_methods.present?

  if self.class.cached_associations.present?
    self.class.cached_associations.each do |assoc|
      expire_association_cache(assoc)
    end
  end
end