Merge branch 'backport-reactive-caching' into 'master'
Back port ReactiveCaching See merge request gitlab-org/gitlab-ce!20836
This commit is contained in:
commit
f7084577bf
|
@ -59,6 +59,9 @@ module ReactiveCaching
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def reactive_cache_updated(*args)
|
||||||
|
end
|
||||||
|
|
||||||
def with_reactive_cache(*args, &blk)
|
def with_reactive_cache(*args, &blk)
|
||||||
bootstrap = !within_reactive_cache_lifetime?(*args)
|
bootstrap = !within_reactive_cache_lifetime?(*args)
|
||||||
Rails.cache.write(alive_reactive_cache_key(*args), true, expires_in: self.class.reactive_cache_lifetime)
|
Rails.cache.write(alive_reactive_cache_key(*args), true, expires_in: self.class.reactive_cache_lifetime)
|
||||||
|
@ -81,8 +84,11 @@ module ReactiveCaching
|
||||||
locking_reactive_cache(*args) do
|
locking_reactive_cache(*args) do
|
||||||
if within_reactive_cache_lifetime?(*args)
|
if within_reactive_cache_lifetime?(*args)
|
||||||
enqueuing_update(*args) do
|
enqueuing_update(*args) do
|
||||||
value = calculate_reactive_cache(*args)
|
key = full_reactive_cache_key(*args)
|
||||||
Rails.cache.write(full_reactive_cache_key(*args), value)
|
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
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -125,6 +125,13 @@ describe ReactiveCaching, :use_clean_rails_memory_store_caching do
|
||||||
go!
|
go!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "calls a reactive_cache_updated only once if content did not change on subsequent update" do
|
||||||
|
expect(instance).to receive(:calculate_reactive_cache).twice
|
||||||
|
expect(instance).to receive(:reactive_cache_updated).once
|
||||||
|
|
||||||
|
2.times { instance.exclusively_update_reactive_cache! }
|
||||||
|
end
|
||||||
|
|
||||||
context 'and #calculate_reactive_cache raises an exception' do
|
context 'and #calculate_reactive_cache raises an exception' do
|
||||||
before do
|
before do
|
||||||
stub_reactive_cache(instance, "preexisting")
|
stub_reactive_cache(instance, "preexisting")
|
||||||
|
|
Loading…
Reference in New Issue