1
0
Fork 0
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:
Rafael França 2019-10-29 15:18:55 -04:00 committed by GitHub
commit 58fe42e07e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 2 deletions

View file

@ -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

View file

@ -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")