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

metadata.rb « cache « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d6c89b5b2c38f9bb9c4733f876d690ee105b79be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# frozen_string_literal: true

module Gitlab
  module Cache
    # Value object for cache metadata
    class Metadata
      VALID_BACKING_RESOURCES = [:cpu, :database, :gitaly, :memory, :unknown].freeze
      DEFAULT_BACKING_RESOURCE = :unknown

      def initialize(
        cache_identifier:,
        feature_category:,
        caller_id: Gitlab::ApplicationContext.current_context_attribute(:caller_id),
        backing_resource: DEFAULT_BACKING_RESOURCE
      )
        @cache_identifier = cache_identifier
        @feature_category = Gitlab::FeatureCategories.default.get!(feature_category)
        @caller_id = caller_id
        @backing_resource = fetch_backing_resource!(backing_resource)
      end

      attr_reader :caller_id, :cache_identifier, :feature_category, :backing_resource

      private

      def fetch_backing_resource!(resource)
        return resource if VALID_BACKING_RESOURCES.include?(resource)

        raise "Unknown backing resource: #{resource}" if Gitlab.dev_or_test_env?

        DEFAULT_BACKING_RESOURCE
      end
    end
  end
end