summaryrefslogtreecommitdiff
path: root/lib/gitlab/cache.rb
blob: 90a0c38ff7b411b5153d79283c7bc7130b199941 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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