50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/cache_ninja.rb', line 50
def clear_cached_data
object_cache_key = "#{self.class.to_s.underscore}/#{id}"
Rails.cache.delete(object_cache_key)
self_n_parents = collect_parent_classes(self.class)
self_n_parents.each do |self_n_parent|
next unless self_n_parent.respond_to?(:cached_associations) && self_n_parent.cached_associations.present?
self_n_parent.cached_associations.each do |association|
Rails.cache.delete("#{self_n_parent.name.downcase}_#{id}_cached_#{association}")
assoc_class_n_id = Array(send(association)).compact.map { |obj| [obj.class, obj.id] }
assoc_class_n_id.each do |assoc_class, assoc_id|
assoc_self_n_parents = collect_parent_classes(assoc_class)
assoc_self_n_parents.each do |assoc_self_n_parent|
Rails.cache.delete("#{assoc_self_n_parent.name.downcase}_#{assoc_id}_cached_#{self_n_parent.name.underscore.singularize}")
Rails.cache.delete("#{assoc_self_n_parent.name.downcase}_#{assoc_id}_cached_#{self_n_parent.name.underscore.pluralize}")
end
end
end
end
end
|