Class: ActiveSupport::Cache::LibmemcachedLocalStore

Inherits:
LibmemcachedStore show all
Includes:
Strategy::LocalCache
Defined in:
lib/active_support/cache/libmemcached_local_store.rb

Constant Summary

Constants inherited from LibmemcachedStore

ActiveSupport::Cache::LibmemcachedStore::DEFAULT_CLIENT_OPTIONS, ActiveSupport::Cache::LibmemcachedStore::DEFAULT_COMPRESS_THRESHOLD, ActiveSupport::Cache::LibmemcachedStore::ESCAPE_KEY_CHARS, ActiveSupport::Cache::LibmemcachedStore::FLAG_COMPRESSED

Instance Attribute Summary

Attributes inherited from LibmemcachedStore

#addresses, #options, #silence

Instance Method Summary collapse

Methods inherited from LibmemcachedStore

#clear, #delete, #exist?, #fetch, #initialize, #mute, #silence!, #stats, #write

Constructor Details

This class inherits a constructor from ActiveSupport::Cache::LibmemcachedStore

Instance Method Details

#decrement(key, amount = 1, options = {}) ⇒ Object

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



74
75
76
77
78
79
80
# 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 = {}) ⇒ Object

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



65
66
67
68
69
70
71
# 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) ⇒ Object

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



30
31
32
33
34
# 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) ⇒ Object

make read multi hit local cache



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# 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