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:
parent
e1a9b3d861
commit
ad7b40c4f7
3 changed files with 12 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue