From 9f07b1edcd2955dc7af166c422309da55372a92c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20L=C3=BCtke?= Date: Tue, 29 Apr 2008 14:57:21 -0400 Subject: By default rails will update keys in memcached when using Rails.cache.write. Use :unless_exist => true flag to prevent existing keys from being overwritten. --- activesupport/lib/active_support/cache/mem_cache_store.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/cache/mem_cache_store.rb b/activesupport/lib/active_support/cache/mem_cache_store.rb index 9b787702b2..ad220a9c2c 100644 --- a/activesupport/lib/active_support/cache/mem_cache_store.rb +++ b/activesupport/lib/active_support/cache/mem_cache_store.rb @@ -29,12 +29,11 @@ module ActiveSupport nil end - # Set key = value if key isn't already set. Pass :force => true - # to unconditionally set key = value. Returns a boolean indicating - # whether the key was set. + # Set key = value. Pass :unless_exist => true if you don't + # want to update the cache if the key is already set. def write(key, value, options = nil) super - method = options && options[:force] ? :set : :add + method = options && options[:unless_exist] ? :add : :set response = @data.send(method, key, value, expires_in(options), raw?(options)) response == Response::STORED rescue MemCache::MemCacheError => e @@ -54,8 +53,8 @@ module ActiveSupport def delete_matched(matcher, options = nil) super raise "Not supported by Memcache" - end - + end + def clear @data.flush_all end -- cgit v1.2.3