Commit 7fcf7647 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'reactive-caching-self-cleanup' into 'master'

Make reactive caching clean up after itself

See merge request gitlab-org/gitlab!20111
parents f8396751 65dabf25
......@@ -129,14 +129,17 @@ module ReactiveCaching
def exclusively_update_reactive_cache!(*args)
locking_reactive_cache(*args) do
key = full_reactive_cache_key(*args)
if within_reactive_cache_lifetime?(*args)
enqueuing_update(*args) do
key = full_reactive_cache_key(*args)
new_value = calculate_reactive_cache(*args)
old_value = Rails.cache.read(key)
Rails.cache.write(key, new_value)
reactive_cache_updated(*args) if new_value != old_value
end
else
Rails.cache.delete(key)
end
end
end
......
---
title: Remove reactive caching value keys once the alive key has expired
merge_request: 20111
author:
type: performance
......@@ -196,6 +196,12 @@ describe ReactiveCaching, :use_clean_rails_memory_store_caching do
2.times { instance.exclusively_update_reactive_cache! }
end
it 'does not delete the value key' do
expect(Rails.cache).to receive(:delete).with(cache_key).never
go!
end
context 'and #calculate_reactive_cache raises an exception' do
before do
stub_reactive_cache(instance, "preexisting")
......@@ -223,6 +229,12 @@ describe ReactiveCaching, :use_clean_rails_memory_store_caching do
go!
end
it 'deletes the value key' do
expect(Rails.cache).to receive(:delete).with(cache_key).once
go!
end
end
context 'when the lease is already taken' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment