lib/catch_cache/flush.rb in catch_cache-0.0.1 vs lib/catch_cache/flush.rb in catch_cache-0.0.2

- old
+ new

@@ -7,17 +7,21 @@ after_commit :flush_cache! define_method(:flush_cache!) do key_callbacks = ClassMethods.key_callbacks - key_callbacks.keys.each do |key| - # Get the uniq id defined in the AR model - uniq_id = instance_exec(&key_callbacks[key]) - # Build the redis cache key - cache_key = "#{key.to_s}_#{uniq_id}" - redis = Redis.new - # Flush the key by setting it to nil - redis.set(cache_key, nil) + begin + key_callbacks.keys.each do |key| + # Get the uniq id defined in the AR model + uniq_id = instance_exec(&key_callbacks[key]) + # Build the redis cache key + cache_key = "#{key.to_s}_#{uniq_id}" + redis = Redis.new + # Flush the key by setting it to nil + redis.set(cache_key, nil) + end + rescue NameError => e + # Nothing was flushed because of an error" end end end end