提交 0d26e47b 编写于 作者: J Jeremy Kemper

MemCacheStore#write and #delete return a boolean indicating whether the operation succeeded


git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8767 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 09d98f13
...@@ -3,6 +3,14 @@ ...@@ -3,6 +3,14 @@
module ActiveSupport module ActiveSupport
module Cache module Cache
class MemCacheStore < Store class MemCacheStore < Store
module Response
STORED = "STORED\r\n"
NOT_STORED = "NOT_STORED\r\n"
EXISTS = "EXISTS\r\n"
NOT_FOUND = "NOT_FOUND\r\n"
DELETED = "DELETED\r\n"
end
attr_reader :addresses attr_reader :addresses
def initialize(*addresses) def initialize(*addresses)
...@@ -21,22 +29,25 @@ def read(key, options = nil) ...@@ -21,22 +29,25 @@ def read(key, options = nil)
end end
# Set key = value if key isn't already set. Pass :force => true # Set key = value if key isn't already set. Pass :force => true
# to unconditionally set key = value. # to unconditionally set key = value. Returns a boolean indicating
# whether the key was set.
def write(key, value, options = {}) def write(key, value, options = {})
super super
method = options[:force] ? :set : :add method = options[:force] ? :set : :add
@data.send(method, key, value, expires_in(options), raw?(options)) response = @data.send(method, key, value, expires_in(options), raw?(options))
response == Response::STORED
rescue MemCache::MemCacheError => e rescue MemCache::MemCacheError => e
logger.error("MemCacheError (#{e}): #{e.message}") logger.error("MemCacheError (#{e}): #{e.message}")
nil false
end end
def delete(key, options = nil) def delete(key, options = nil)
super super
@data.delete(key, expires_in(options)) response = @data.delete(key, expires_in(options))
response == Response::DELETED
rescue MemCache::MemCacheError => e rescue MemCache::MemCacheError => e
logger.error("MemCacheError (#{e}): #{e.message}") logger.error("MemCacheError (#{e}): #{e.message}")
nil false
end end
def delete_matched(matcher, options = nil) def delete_matched(matcher, options = nil)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册