diff options
Diffstat (limited to 'lib/gitlab/cache.rb')
-rw-r--r-- | lib/gitlab/cache.rb | 18 |
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 |