debian-mirror-gitlab/lib/gitlab/cache.rb

19 lines
428 B
Ruby
Raw Normal View History

2021-06-08 01:23:25 +05:30
# 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