Class: ActiveSupport::Cache::SpymemcachedStore
- Inherits:
-
Store
- Object
- Store
- ActiveSupport::Cache::SpymemcachedStore
- Defined in:
- lib/active_support/cache/spymemcached_store.rb
Defined Under Namespace
Modules: LocalCacheWithRaw
Instance Method Summary collapse
-
#clear(options = nil) ⇒ Object
Clear the entire cache.
-
#decrement(name, amount = 1, options = nil) ⇒ Object
Decrement an integer value in the cache.
-
#increment(name, amount = 1, options = nil) ⇒ Object
Increment an integer value in the cache.
-
#initialize(*addresses) ⇒ SpymemcachedStore
constructor
A new instance of SpymemcachedStore.
-
#read_multi(*names) ⇒ Object
Read multiple values at once from the cache.
-
#stats ⇒ Object
Get the statistics from the memcached servers.
Constructor Details
#initialize(*addresses) ⇒ SpymemcachedStore
Returns a new instance of SpymemcachedStore.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/active_support/cache/spymemcached_store.rb', line 8 def initialize(*addresses) addresses = addresses.flatten = addresses. super() unless [String, Spymemcached, NilClass].include?(addresses.first.class) raise ArgumentError, "First argument must be an empty array, an array of hosts or a Spymemcached instance." end @client = if addresses.first.is_a?(Spymemcached) addresses.first else = .dup UNIVERSAL_OPTIONS.each{|name| .delete(name)} Spymemcached.new(addresses, ) end extend Strategy::LocalCache extend LocalCacheWithRaw end |
Instance Method Details
#clear(options = nil) ⇒ Object
Clear the entire cache. Be careful with this method since it could affect other processes if shared cache is being used.
The options hash is passed to the underlying cache implementation.
All implementations may not support this method.
85 86 87 88 89 90 |
# File 'lib/active_support/cache/spymemcached_store.rb', line 85 def clear( = nil) @client.flush_all rescue Spymemcached::Error => e logger.error("Spymemcached::Error (#{e}): #{e.message}") if logger nil end |
#decrement(name, amount = 1, options = nil) ⇒ Object
Decrement an integer value in the cache.
Options are passed to the underlying cache implementation.
All implementations may not support this method.
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/active_support/cache/spymemcached_store.rb', line 68 def decrement(name, amount = 1, = nil) = () instrument(:decrement, name, :amount => amount) do @client.decr(name, amount) end rescue Spymemcached::Error => e logger.error("Spymemcached::Error (#{e}): #{e.message}") if logger nil end |
#increment(name, amount = 1, options = nil) ⇒ Object
Increment an integer value in the cache.
Options are passed to the underlying cache implementation.
All implementations may not support this method.
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/active_support/cache/spymemcached_store.rb', line 52 def increment(name, amount = 1, = nil) = () instrument(:increment, name, :amount => amount) do @client.incr(name, amount) end rescue Spymemcached::Error => e logger.error("Spymemcached::Error (#{e}): #{e.message}") if logger nil end |
#read_multi(*names) ⇒ Object
Read multiple values at once from the cache. Options can be passed in the last argument.
Some cache implementation may optimize this method.
Returns a hash mapping the names provided to the values found.
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/active_support/cache/spymemcached_store.rb', line 34 def read_multi(*names) = names. = () keys_to_names = Hash[names.map{|name| [namespaced_key(name, ), name]}] raw_values = @client.get_multi(keys_to_names.keys) values = {} raw_values.each do |key, value| entry = deserialize_entry(value) values[keys_to_names[key]] = entry.value unless entry.expired? end values end |
#stats ⇒ Object
Get the statistics from the memcached servers.
93 94 95 |
# File 'lib/active_support/cache/spymemcached_store.rb', line 93 def stats @client.stats end |