Permalink
Browse files

Ensure that read_entry returns an Entry

Also updated formatting
  • Loading branch information...
1 parent 245d5c5 commit cf3819b21f006e4d6060e42a3bb7ff01f700f116 @jstorimer committed Oct 13, 2010
Showing with 33 additions and 35 deletions.
  1. +33 −35 lib/active_support/cache/libmemcached_store.rb
@@ -31,8 +31,33 @@ def initialize(*addresses)
@cache = Memcached.new(@addresses, @options.reverse_merge(DEFAULT_OPTIONS))
end
+ def increment(key, amount=1)
+ log 'incrementing', key, amount
+ @cache.incr(key, amount)
+ rescue Memcached::Error
+ nil
+ end
+
+ def decrement(key, amount=1)
+ log 'decrementing', key, amount
+ @cache.decr(key, amount)
+ rescue Memcached::Error
+ nil
+ end
+
+ def clear
+ @cache.flush
+ end
+
+ def stats
+ @cache.stats
+ end
+
+ protected
+
def read_entry(key, options = nil)
- @cache.get(key, marshal?(options))
+ entry = @cache.get(key, marshal?(options))
+ entry.is_a?(Entry) ? entry : Entry.new(entry)
rescue Memcached::NotFound
nil
rescue Memcached::Error => e
@@ -59,46 +84,19 @@ def delete_entry(key, options = nil)
false
end
- def exist?(key, options = nil)
- !read(key, options).nil?
- end
+ private
- def increment(key, amount=1)
- log 'incrementing', key, amount
- @cache.incr(key, amount)
- rescue Memcached::Error
- nil
+ def expires_in(options)
+ (options || {})[:expires_in] || 0
end
- def decrement(key, amount=1)
- log 'decrementing', key, amount
- @cache.decr(key, amount)
- rescue Memcached::Error
- nil
+ def marshal?(options)
+ !(options || {})[:raw]
end
-
- def clear
- @cache.flush
- end
-
- def stats
- @cache.stats
+ def log_error(exception)
+ logger.error "MemcachedError (#{exception.inspect}): #{exception.message}" if logger && !@logger_off
end
-
- private
-
- def expires_in(options)
- (options || {})[:expires_in] || 0
- end
-
- def marshal?(options)
- !(options || {})[:raw]
- end
-
- def log_error(exception)
- logger.error "MemcachedError (#{exception.inspect}): #{exception.message}" if logger && !@logger_off
- end
end
end
end

0 comments on commit cf3819b

Please sign in to comment.