Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-05-19 18:44:42 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-05-19 18:44:42 +0300
commit4555e1b21c365ed8303ffb7a3325d773c9b8bf31 (patch)
tree5423a1c7516cffe36384133ade12572cf709398d /lib/gitlab/cache.rb
parente570267f2f6b326480d284e0164a6464ba4081bc (diff)
Add latest changes from gitlab-org/gitlab@13-12-stable-eev13.12.0-rc42
Diffstat (limited to 'lib/gitlab/cache.rb')
-rw-r--r--lib/gitlab/cache.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/gitlab/cache.rb b/lib/gitlab/cache.rb
new file mode 100644
index 00000000000..90a0c38ff7b
--- /dev/null
+++ b/lib/gitlab/cache.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Cache
+ class << self
+ # Utility method for performing a fetch but only
+ # once per request, storing the returned value in
+ # the request store, if active.
+ def fetch_once(key, **kwargs)
+ Gitlab::SafeRequestStore.fetch(key) do
+ Rails.cache.fetch(key, **kwargs) do
+ yield
+ end
+ end
+ end
+ end
+ end
+end