summaryrefslogtreecommitdiff
path: root/app/models/concerns/reactive_caching.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-16 12:08:32 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-16 12:08:32 +0000
commitc158fa8d69c704663d289341a014c44c062cda88 (patch)
treed0cac82a9ac9e9ad28bb0030266eb8d5dc91fbbc /app/models/concerns/reactive_caching.rb
parentb806264d29b8d52ccb78a41dcc3d67f2b040700c (diff)
downloadgitlab-ce-c158fa8d69c704663d289341a014c44c062cda88.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/concerns/reactive_caching.rb')
-rw-r--r--app/models/concerns/reactive_caching.rb75
1 files changed, 2 insertions, 73 deletions
diff --git a/app/models/concerns/reactive_caching.rb b/app/models/concerns/reactive_caching.rb
index 45fbbef9225..4b9896343c6 100644
--- a/app/models/concerns/reactive_caching.rb
+++ b/app/models/concerns/reactive_caching.rb
@@ -1,78 +1,7 @@
# frozen_string_literal: true
-# The ReactiveCaching concern is used to fetch some data in the background and
-# store it in the Rails cache, keeping it up-to-date for as long as it is being
-# requested. If the data hasn't been requested for +reactive_cache_lifetime+,
-# it stop being refreshed, and then be removed.
-#
-# Example of use:
-#
-# class Foo < ApplicationRecord
-# include ReactiveCaching
-#
-# after_save :clear_reactive_cache!
-#
-# def calculate_reactive_cache
-# # Expensive operation here. The return value of this method is cached
-# end
-#
-# def result
-# with_reactive_cache do |data|
-# # ...
-# end
-# end
-# end
-#
-# In this example, the first time `#result` is called, it will return `nil`.
-# However, it will enqueue a background worker to call `#calculate_reactive_cache`
-# and set an initial cache lifetime of ten minutes.
-#
-# The background worker needs to find or generate the object on which
-# `with_reactive_cache` was called.
-# The default behaviour can be overridden by defining a custom
-# `reactive_cache_worker_finder`.
-# Otherwise the background worker will use the class name and primary key to get
-# the object using the ActiveRecord find_by method.
-#
-# class Bar
-# include ReactiveCaching
-#
-# self.reactive_cache_key = ->() { ["bar", "thing"] }
-# self.reactive_cache_worker_finder = ->(_id, *args) { from_cache(*args) }
-#
-# def self.from_cache(var1, var2)
-# # This method will be called by the background worker with "bar1" and
-# # "bar2" as arguments.
-# new(var1, var2)
-# end
-#
-# def initialize(var1, var2)
-# # ...
-# end
-#
-# def calculate_reactive_cache
-# # Expensive operation here. The return value of this method is cached
-# end
-#
-# def result
-# with_reactive_cache("bar1", "bar2") do |data|
-# # ...
-# end
-# end
-# end
-#
-# Each time the background job completes, it stores the return value of
-# `#calculate_reactive_cache`. It is also re-enqueued to run again after
-# `reactive_cache_refresh_interval`, so keeping the stored value up to date.
-# Calculations are never run concurrently.
-#
-# Calling `#result` while a value is in the cache will call the block given to
-# `#with_reactive_cache`, yielding the cached value. It will also extend the
-# lifetime by `reactive_cache_lifetime`.
-#
-# Once the lifetime has expired, no more background jobs will be enqueued and
-# calling `#result` will again return `nil` - starting the process all over
-# again
+# The usage of the ReactiveCaching module is documented here:
+# https://docs.gitlab.com/ee/development/utilities.html#reactivecaching
module ReactiveCaching
extend ActiveSupport::Concern