From 13d8777b63f93426f6a1101f066cc3cf218109d3 Mon Sep 17 00:00:00 2001 From: Mike Evans Date: Thu, 11 Oct 2012 15:46:30 -0400 Subject: [PATCH] Padding expires_in by 5 minutes on dalli key write to facilitate :race_condition_ttl working correctly. --- activesupport/lib/active_support/cache/mem_cache_store.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/activesupport/lib/active_support/cache/mem_cache_store.rb b/activesupport/lib/active_support/cache/mem_cache_store.rb index 5aa78cc9f3..17450fe4d0 100644 --- a/activesupport/lib/active_support/cache/mem_cache_store.rb +++ b/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 -- GitLab