Browse files

Padding expires_in by 5 minutes on dalli key write to facilitate :rac…

…e_condition_ttl working correctly.
  • Loading branch information...
1 parent 888a7a5 commit 13d8777b63f93426f6a1101f066cc3cf218109d3 @mje113 mje113 committed Oct 11, 2012
Showing with 4 additions and 0 deletions.
  1. +4 −0 activesupport/lib/active_support/cache/mem_cache_store.rb
@@ -132,6 +132,10 @@ def write_entry(key, entry, options) # :nodoc:
method = options && options[:unless_exist] ? :add : :set
value = options[:raw] ? entry.value.to_s : entry
expires_in = options[:expires_in].to_i
+ if expires_in > 0 && !options[:raw]
+ # Set the memcache expire a few minutes in the future to support race condition ttls on read
+ expires_in += 5.minutes
+ end
@data.send(method, escape_key(key), value, expires_in, options)
rescue Dalli::DalliError => e
logger.error("DalliError (#{e}): #{e.message}") if logger

2 comments on commit 13d8777


annaswims replied Jan 20, 2015

@mje113 Could you explain why adding 5 minutes to the expires_in is the appropriate thing to do here? I was using dali 2.6.4 and set the expires_in to 30.days. Memcached interprets anything over 30 days as a timestamp and adding 5 minutes made it greater than 30 days, therefore my cache didn't work.


mje113 replied Jan 21, 2015

The issue resolved in this commit was bringing back the functionality that supported the :race_condition_ttl option that had been accidentally (I believe?) removed. I agree that that is problematic with a 30 day cache, but I think that's a question rails core devs should answer.

Please sign in to comment.