class ActiveSupport::Cache::LibmemcachedLocalStore

Public Instance Methods

decrement(key, amount = 1, options={}) click to toggle source

memcached returns a fixnum on decrement, but the value that is stored is raw / a string

Calls superclass method
# File lib/active_support/cache/libmemcached_local_store.rb, line 74
def decrement(key, amount = 1, options={})
  result = super
  if result && (cache = local_cache)
    cache.write(key, result.to_s)
  end
  result
end
increment(key, amount = 1, options={}) click to toggle source

memcached returns a fixnum on increment, but the value that is stored is raw / a string

Calls superclass method
# File lib/active_support/cache/libmemcached_local_store.rb, line 65
def increment(key, amount = 1, options={})
  result = super
  if result && (cache = local_cache)
    cache.write(key, result.to_s)
  end
  result
end
read(*args) click to toggle source

if we read from local_cache then the return value from read_entry will be an Entry, so convert it to it's value

Calls superclass method
# File lib/active_support/cache/libmemcached_local_store.rb, line 30
def read(*args)
  result = super
  result = result.value if result.is_a?(ActiveSupport::Cache::Entry)
  result
end
read_multi(*names) click to toggle source

make read multi hit local cache

Calls superclass method
# File lib/active_support/cache/libmemcached_local_store.rb, line 37
def read_multi(*names)
  return super unless cache = local_cache

  options = names.extract_options!

  missing_names = []

  # We write raw values to the local cache, unlike rails MemcachedStore, so we cannot use local_cache.read_multi.
  # Once read_multi_entry is available we can switch to that.
  results = names.each_with_object({}) do |name, results|
    value = local_cache.fetch_entry(name) do
      missing_names << name
      nil
    end
    results[name] = value unless value.nil?
  end

  if missing_names.any?
    missing_names << options
    missing = super(*missing_names)
    missing.each { |k,v| cache.write_entry(k, v, nil) }
    results.merge!(missing)
  end

  results
end

Private Instance Methods

read_entry(key, options) click to toggle source

when trying to do a raw read we want the marshaled value to behave the same as memcached

Calls superclass method
# File lib/active_support/cache/libmemcached_local_store.rb, line 85
def read_entry(key, options)
  entry = super

  if options && options[:raw] && local_cache && entry && !entry.is_a?(Entry)
    entry = Marshal.dump(entry)
  end

  entry
end