Fix MemoryStore#write(name, val, unless_exist: true) with expired entry

This commit is contained in:
Alan Savage 2022-05-11 11:20:01 -07:00
parent e1a9b3d861
commit ad7b40c4f7
3 changed files with 12 additions and 1 deletions

View File

@ -1,3 +1,8 @@
* `ActiveSupport::Cache::MemoryStore#write(name, val, unless_exist:true)` now
correctly writes expired keys.
*Alan Savage*
* `ActiveSupport::ErrorReporter` now accepts and forward a `source:` parameter.
This allow libraries to signal the origin of the errors, and reporters

View File

@ -166,7 +166,7 @@ module ActiveSupport
def write_entry(key, entry, **options)
payload = serialize_entry(entry, **options)
synchronize do
return false if options[:unless_exist] && @data.key?(key)
return false if options[:unless_exist] && exist?(key)
old_payload = @data[key]
if old_payload

View File

@ -156,4 +156,10 @@ class MemoryStorePruningTest < ActiveSupport::TestCase
@cache.write(1, nil)
assert_equal false, @cache.write(1, "aaaaaaaaaa", unless_exist: true)
end
def test_write_expired_value_with_unless_exist
assert_equal true, @cache.write(1, "aaaa", expires_in: 1.second)
travel 2.seconds
assert_equal true, @cache.write(1, "bbbb", expires_in: 1.second, unless_exist: true)
end
end