Permalink
Browse files

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.
  • Loading branch information...
tobi committed Apr 29, 2008
1 parent bfb54ae commit 9f07b1edcd2955dc7af166c422309da55372a92c
Showing with 5 additions and 6 deletions.
  1. +5 −6 activesupport/lib/active_support/cache/mem_cache_store.rb
@@ -29,12 +29,11 @@ def read(key, options = nil)
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 @@ def delete(key, options = nil)
def delete_matched(matcher, options = nil)
super
raise "Not supported by Memcache"
- end
-
+ end
+
def clear
@data.flush_all
end

0 comments on commit 9f07b1e

Please sign in to comment.