Module: ActiveSupport::Cache::RedisStoreCas
- Defined in:
- lib/active_support/cache/redis_store_with_cas.rb
Instance Attribute Summary collapse
-
#read_only ⇒ Object
Returns the value of attribute read_only.
Instance Method Summary collapse
Instance Attribute Details
#read_only ⇒ Object
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,=nil = () key = normalize_key(name, ) instrument(:cas, name, ) do ttl = cas_expiration @data.cas(key,ttl) do |entry| value = yield entry.value break true if read_only [:raw].present? ? value : Entry.new(value, ) 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) = names. return if names.empty? = () keys_to_names = Hash[names.map { |name| [normalize_key(name, ), name] }] instrument(:cas_multi, names, ) do @data.cas_multi(*(keys_to_names.keys), {:expires_in => cas_expiration()}) 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, ),[:raw].present? ? value : Entry.new(value, )] end Hash[mapped_values] end true end end |