Module: ActiveSupport::Cache::RedisStoreCas

Defined in:
lib/active_support/cache/redis_store_with_cas.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#read_onlyObject

Returns the value of attribute read_only.



9
10
11
# File 'lib/active_support/cache/redis_store_with_cas.rb', line 9

def read_only
  @read_only
end

Instance Method Details

#cas(name, options = nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/active_support/cache/redis_store_with_cas.rb', line 11

def cas name,options=nil
  options = merged_options(options)
  key = normalize_key(name, options)
  instrument(:cas, name, options) do
    ttl = cas_expiration options
    @data.cas(key,ttl) do |entry|
      value = yield entry.value
      break true if read_only
      options[:raw].present? ? value : Entry.new(value, options)
    end
  end
end

#cas_multi(*names) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/active_support/cache/redis_store_with_cas.rb', line 24

def cas_multi(*names)
  options = names.extract_options!
  return if names.empty?

  options = merged_options(options)
  keys_to_names = Hash[names.map { |name| [normalize_key(name, options), name] }]

  instrument(:cas_multi, names, options) do
    @data.cas_multi(*(keys_to_names.keys), {:expires_in => cas_expiration(options)}) do |raw_values|
      values = {}
      raw_values.each do |key, entry|
        values[keys_to_names[key]] = entry.value unless entry.expired?
      end
      values = yield values
      break true if read_only
      mapped_values = values.map do |name,value|
        [normalize_key(name, options),options[:raw].present? ? value : Entry.new(value, options)]
      end
      Hash[mapped_values]
    end
    true
  end

end