未验证 提交 950bf54c 编写于 作者: M Michael Grosser 提交者: GitHub

Using write with unless_exist + expires_in should unlock after the given...

Using write with unless_exist + expires_in should unlock after the given expires_in and not 5 minutes later (#40260)
Co-authored-by: NJye Lee <jyelee124@gmail.com>
Co-authored-by: NEugene Kenny <elkenny@gmail.com>
上级 5bf8b3e0
* 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 @@ def write_entry(key, entry, **options)
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 @@ def test_no_multiple_compress
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册