aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/cache
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2008-02-01 08:25:58 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2008-02-01 08:25:58 +0000
commit0d26e47b296e29dc48da1b31949d7b7adfb40553 (patch)
tree80dcf812d165a03a55513fa27604ffd8f1659096 /activesupport/lib/active_support/cache
parent09d98f13316c76a61cbceaa4157c45ac4924803c (diff)
downloadrails-0d26e47b296e29dc48da1b31949d7b7adfb40553.tar.gz
rails-0d26e47b296e29dc48da1b31949d7b7adfb40553.tar.bz2
rails-0d26e47b296e29dc48da1b31949d7b7adfb40553.zip
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
Diffstat (limited to 'activesupport/lib/active_support/cache')
-rw-r--r--activesupport/lib/active_support/cache/mem_cache_store.rb21
1 files changed, 16 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/cache/mem_cache_store.rb b/activesupport/lib/active_support/cache/mem_cache_store.rb
index 12b450ed86..5312271330 100644
--- a/activesupport/lib/active_support/cache/mem_cache_store.rb
+++ b/activesupport/lib/active_support/cache/mem_cache_store.rb
@@ -3,6 +3,14 @@ require 'memcache'
module ActiveSupport
module Cache
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
def initialize(*addresses)
@@ -21,22 +29,25 @@ module ActiveSupport
end
# 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 = {})
super
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
logger.error("MemCacheError (#{e}): #{e.message}")
- nil
+ false
end
def delete(key, options = nil)
super
- @data.delete(key, expires_in(options))
+ response = @data.delete(key, expires_in(options))
+ response == Response::DELETED
rescue MemCache::MemCacheError => e
logger.error("MemCacheError (#{e}): #{e.message}")
- nil
+ false
end
def delete_matched(matcher, options = nil)