mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #37587 from Shopify/fix-local-cache-leak
Duplicate the cached value before writing it in the local cache
This commit is contained in:
commit
58fe42e07e
2 changed files with 22 additions and 2 deletions
|
@ -64,8 +64,9 @@ module ActiveSupport
|
|||
values
|
||||
end
|
||||
|
||||
def write_entry(key, value, **options)
|
||||
@data[key] = value
|
||||
def write_entry(key, entry, **options)
|
||||
entry.dup_value!
|
||||
@data[key] = entry
|
||||
true
|
||||
end
|
||||
|
||||
|
|
|
@ -150,6 +150,25 @@ module LocalCacheBehavior
|
|||
end
|
||||
end
|
||||
|
||||
def test_initial_object_mutation_after_write
|
||||
@cache.with_local_cache do
|
||||
initial = +"bar"
|
||||
@cache.write("foo", initial)
|
||||
initial << "baz"
|
||||
assert_equal "bar", @cache.read("foo")
|
||||
end
|
||||
end
|
||||
|
||||
def test_initial_object_mutation_after_fetch
|
||||
@cache.with_local_cache do
|
||||
initial = +"bar"
|
||||
@cache.fetch("foo") { initial }
|
||||
initial << "baz"
|
||||
assert_equal "bar", @cache.read("foo")
|
||||
assert_equal "bar", @cache.fetch("foo")
|
||||
end
|
||||
end
|
||||
|
||||
def test_middleware
|
||||
app = lambda { |env|
|
||||
result = @cache.write("foo", "bar")
|
||||
|
|
Loading…
Reference in a new issue