Class: ActiveSupport::Cache::MemCacheStore
- Defined in:
- lib/active_support/cache/mem_cache_store.rb
Direct Known Subclasses
Defined Under Namespace
Modules: Response
Instance Attribute Summary collapse
-
#addresses ⇒ Object
readonly
Returns the value of attribute addresses.
Instance Method Summary collapse
- #clear ⇒ Object
- #decrement(key, amount = 1) ⇒ Object
- #delete(key, options = nil) ⇒ Object
- #delete_matched(matcher, options = nil) ⇒ Object
- #exist?(key, options = nil) ⇒ Boolean
- #increment(key, amount = 1) ⇒ Object
-
#initialize(*addresses) ⇒ MemCacheStore
constructor
A new instance of MemCacheStore.
- #read(key, options = nil) ⇒ Object
- #stats ⇒ Object
-
#write(key, value, options = nil) ⇒ Object
Set key = value.
Methods inherited from Store
Constructor Details
#initialize(*addresses) ⇒ MemCacheStore
Returns a new instance of MemCacheStore.
16 17 18 19 20 21 22 |
# File 'lib/active_support/cache/mem_cache_store.rb', line 16 def initialize(*addresses) addresses = addresses.flatten = addresses. addresses = ["localhost"] if addresses.empty? @addresses = addresses @data = MemCache.new(addresses, ) end |
Instance Attribute Details
#addresses ⇒ Object (readonly)
Returns the value of attribute addresses.
14 15 16 |
# File 'lib/active_support/cache/mem_cache_store.rb', line 14 def addresses @addresses end |
Instance Method Details
#clear ⇒ Object
82 83 84 |
# File 'lib/active_support/cache/mem_cache_store.rb', line 82 def clear @data.flush_all end |
#decrement(key, amount = 1) ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/active_support/cache/mem_cache_store.rb', line 68 def decrement(key, amount = 1) log("decrement", key, amount) response = data.decr(key, amount) response == Response::NOT_FOUND ? nil : response rescue MemCache::MemCacheError nil end |
#delete(key, options = nil) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/active_support/cache/mem_cache_store.rb', line 44 def delete(key, = nil) super response = @data.delete(key, expires_in()) response == Response::DELETED rescue MemCache::MemCacheError => e logger.error("MemCacheError (#{e}): #{e.}") false end |
#delete_matched(matcher, options = nil) ⇒ Object
77 78 79 80 |
# File 'lib/active_support/cache/mem_cache_store.rb', line 77 def delete_matched(matcher, = nil) super raise "Not supported by Memcache" end |
#exist?(key, options = nil) ⇒ Boolean
53 54 55 56 57 |
# File 'lib/active_support/cache/mem_cache_store.rb', line 53 def exist?(key, = nil) # Doesn't call super, cause exist? in memcache is in fact a read # But who cares? Reading is very fast anyway !read(key, ).nil? end |
#increment(key, amount = 1) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/active_support/cache/mem_cache_store.rb', line 59 def increment(key, amount = 1) log("incrementing", key, amount) response = @data.incr(key, amount) response == Response::NOT_FOUND ? nil : response rescue MemCache::MemCacheError nil end |
#read(key, options = nil) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/active_support/cache/mem_cache_store.rb', line 24 def read(key, = nil) super @data.get(key, raw?()) rescue MemCache::MemCacheError => e logger.error("MemCacheError (#{e}): #{e.}") nil end |
#stats ⇒ Object
86 87 88 |
# File 'lib/active_support/cache/mem_cache_store.rb', line 86 def stats @data.stats end |
#write(key, value, options = nil) ⇒ Object
Set key = value. Pass :unless_exist => true if you don’t want to update the cache if the key is already set.
34 35 36 37 38 39 40 41 42 |
# File 'lib/active_support/cache/mem_cache_store.rb', line 34 def write(key, value, = nil) super method = && [:unless_exist] ? :add : :set response = @data.send(method, key, value, expires_in(), raw?()) response == Response::STORED rescue MemCache::MemCacheError => e logger.error("MemCacheError (#{e}): #{e.}") false end |