1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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. * `ActiveSupport::ErrorReporter` now accepts and forward a `source:` parameter.
This allow libraries to signal the origin of the errors, and reporters 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) def write_entry(key, entry, **options)
payload = serialize_entry(entry, **options) payload = serialize_entry(entry, **options)
synchronize do synchronize do
return false if options[:unless_exist] && @data.key?(key) return false if options[:unless_exist] && exist?(key)
old_payload = @data[key] old_payload = @data[key]
if old_payload if old_payload

View file

@ -156,4 +156,10 @@ class MemoryStorePruningTest < ActiveSupport::TestCase
@cache.write(1, nil) @cache.write(1, nil)
assert_equal false, @cache.write(1, "aaaaaaaaaa", unless_exist: true) assert_equal false, @cache.write(1, "aaaaaaaaaa", unless_exist: true)
end 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 end