diff options
author | Shinya Maeda <shinya@gitlab.com> | 2018-07-25 19:03:18 +0900 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2018-07-25 19:03:18 +0900 |
commit | c807a41849ad83e2a8ad3f206c454a46bff602d2 (patch) | |
tree | 642acf5c4e77516f1c4a33d4d356f69fd56501c8 /app/models/concerns/reactive_caching.rb | |
parent | 6cb30f83255f0982646fea688f2fe275a3b22cc7 (diff) | |
download | gitlab-ce-c807a41849ad83e2a8ad3f206c454a46bff602d2.tar.gz |
Backport reactive caching
Diffstat (limited to 'app/models/concerns/reactive_caching.rb')
-rw-r--r-- | app/models/concerns/reactive_caching.rb | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/app/models/concerns/reactive_caching.rb b/app/models/concerns/reactive_caching.rb index be0a5b49012..9155d82d567 100644 --- a/app/models/concerns/reactive_caching.rb +++ b/app/models/concerns/reactive_caching.rb @@ -59,6 +59,9 @@ module ReactiveCaching raise NotImplementedError end + def reactive_cache_updated(*args) + end + def with_reactive_cache(*args, &blk) bootstrap = !within_reactive_cache_lifetime?(*args) 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 if within_reactive_cache_lifetime?(*args) enqueuing_update(*args) do - value = calculate_reactive_cache(*args) - Rails.cache.write(full_reactive_cache_key(*args), value) + 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 end end |