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