提交 9f07b1ed 编写于 作者: T Tobias Lütke

By default rails will update keys in memcached when using Rails.cache.write....

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.
上级 bfb54aef
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册