module ActiveSupport::Cache::RedisStoreCas

Attributes

read_only[RW]

Public Instance Methods

cas(name,options=nil) { |value| ... } click to toggle source
# 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
    with do |c|
      c.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
end
cas_multi(*names) { |values| ... } click to toggle source
# File lib/active_support/cache/redis_store_with_cas.rb, line 26
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
    with do |c|
      c.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
    end
    true
  end

end

Private Instance Methods

cas_expiration(options) click to toggle source
# File lib/active_support/cache/redis_store_with_cas.rb, line 55
def cas_expiration(options)
  if options[:expires_in].present? && options[:race_condition_ttl].present? && options[:raw].blank?
    options[:expires_in].to_f + options[:race_condition_ttl].to_f
  else
    nil
  end
end