mirror of https://github.com/rails/rails
Using write with unless_exist + expires_in should unlock after the given expires_in and not 5 minutes later (#40260)
Co-authored-by: Jye Lee <jyelee124@gmail.com> Co-authored-by: Eugene Kenny <elkenny@gmail.com>
This commit is contained in:
parent
5bf8b3e07d
commit
950bf54cda
|
@ -1,3 +1,7 @@
|
|||
* Fix bug to make memcached write_entry expire correctly with unless_exist
|
||||
|
||||
*Jye Lee*
|
||||
|
||||
* Add `ActiveSupport::Duration` conversion methods
|
||||
|
||||
`in_seconds`, `in_minutes`, `in_hours`, `in_days`, `in_weeks`, `in_months`, and `in_years` return the respective duration covered.
|
||||
|
|
|
@ -144,7 +144,7 @@ module ActiveSupport
|
|||
method = 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]
|
||||
if options[:race_condition_ttl] && 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
|
||||
|
|
|
@ -161,6 +161,13 @@ class MemCacheStoreTest < ActiveSupport::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_unless_exist_expires_when_configured
|
||||
cache = ActiveSupport::Cache.lookup_store(:mem_cache_store)
|
||||
assert_called_with cache.instance_variable_get(:@data), :add, [ "foo", ActiveSupport::Cache::Entry, 1, Hash ] do
|
||||
cache.write("foo", "bar", expires_in: 1, unless_exist: true)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def random_string(length)
|
||||
(0...length).map { (65 + rand(26)).chr }.join
|
||||
|
|
Loading…
Reference in New Issue