lib/cacheable.rb in simple_cacheable-1.1.3 vs lib/cacheable.rb in simple_cacheable-1.1.4

- old
+ new

@@ -9,11 +9,11 @@ def with_key self.cached_key = true class_eval <<-EOF - after_update :expire_key_cache + after_commit :expire_key_cache, :on => :update def self.find_cached(id) Rails.cache.fetch "#{name.tableize}/" + id.to_i.to_s do self.find(id) end @@ -23,11 +23,11 @@ def with_attribute(*attributes) self.cached_indices = attributes.inject({}) { |indices, attribute| indices[attribute] = {} } class_eval <<-EOF - after_update :expire_attribute_cache + after_commit :expire_attribute_cache, :on => :update EOF attributes.each do |attribute| class_eval <<-EOF def self.find_cached_by_#{attribute}(value) @@ -43,11 +43,11 @@ def with_method(*methods) self.cached_methods = methods class_eval <<-EOF - after_update :expire_method_cache + after_commit :expire_method_cache, :on => :update EOF methods.each do |meth| class_eval <<-EOF def cached_#{meth} @@ -74,11 +74,10 @@ else reverse_association = association.klass.reflect_on_all_associations(:belongs_to).find { |reverse_association| reverse_association.options[:polymorphic] ? reverse_association.name == association.options[:as] : reverse_association.klass == self } association.klass.class_eval <<-EOF - after_save :expire_#{association_name}_cache - after_destroy :expire_#{association_name}_cache + after_commit :expire_#{association_name}_cache def expire_#{association_name}_cache if respond_to? :cached_#{reverse_association.name} cached_#{reverse_association.name}.expire_association_cache(:#{association_name}) else