class ActiveSupport::Cache::SpymemcachedStore
Public Class Methods
namespace
# File lib/active_support/cache/spymemcached_store.rb, line 9 def initialize(*addresses) addresses = addresses.flatten options = addresses.extract_options! super(options) 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 mem_cache_options = options.dup UNIVERSAL_OPTIONS.each{|name| mem_cache_options.delete(name)} Spymemcached.new(addresses, mem_cache_options) end extend Strategy::LocalCache extend LocalCacheWithRaw end
Public Instance Methods
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.
# File lib/active_support/cache/spymemcached_store.rb, line 86 def clear(options = nil) @client.flush_all rescue Spymemcached::Error => e logger.error("Spymemcached::Error (#{e}): #{e.message}") if logger nil end
Decrement an integer value in the cache.
Options are passed to the underlying cache implementation.
All implementations may not support this method.
# File lib/active_support/cache/spymemcached_store.rb, line 69 def decrement(name, amount = 1, options = nil) options = merged_options(options) 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 an integer value in the cache.
Options are passed to the underlying cache implementation.
All implementations may not support this method.
# File lib/active_support/cache/spymemcached_store.rb, line 53 def increment(name, amount = 1, options = nil) options = merged_options(options) 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 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.
# File lib/active_support/cache/spymemcached_store.rb, line 35 def read_multi(*names) options = names.extract_options! options = merged_options(options) keys_to_names = Hash[names.map{|name| [namespaced_key(name, options), 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
Get the statistics from the memcached servers.
# File lib/active_support/cache/spymemcached_store.rb, line 94 def stats @client.stats end
Protected Instance Methods
# File lib/active_support/cache/spymemcached_store.rb, line 134 def deserialize_entry(raw_value) if raw_value entry = Marshal.load(raw_value) rescue raw_value entry.is_a?(Entry) ? entry : Entry.new(entry) else nil end end