Module: MemCacheStorePatch

Defined in:
lib/mem_cache_store_patch.rb

Overview

monky patch support touch interface for ActiveSupport::Cache::MemCacheStore

Instance Method Summary collapse

Instance Method Details

#read_cas(name, options = nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/mem_cache_store_patch.rb', line 13

def read_cas(name, options = nil)
  options ||= {}
  key = namespaced_key(name, options)

  instrument(:get_cas, key) do |_payload|
    @data.get_cas(key)
  end
rescue Dalli::DalliError => e
  logger.error("DalliError: #{e.message}") if logger
  raise if raise_errors?
  false
end

#touch(name, ttl = nil) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/mem_cache_store_patch.rb', line 4

def touch(name, ttl = nil)
  key = namespaced_key(name, options)
  ttl ||= options[:expires_in].to_i if options[:expires_in]
  @data.touch(key, ttl)
rescue Dalli::DalliError => e
  logger.error("DalliError (#{e}): #{e.message}") if logger
  nil
end

#write_cas(name, value, options = nil) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/mem_cache_store_patch.rb', line 26

def write_cas(name, value, options = nil)
  options ||= {}
  key = namespaced_key(name, options)
  expires_in = options[:expires_in]

  instrument(:set_cas, key, value) do |_payload|
    cas = options.delete(:cas) || 0
    expires_in = options.delete(:expires_in)
    @data.set_cas(key, value, cas, expires_in, options)
  end
rescue Dalli::DalliError => e
  logger.error("DalliError: #{e.message}") if logger
  raise if raise_errors?
  false
end