2023-04-23 21:23:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Cache
|
|
|
|
# Value object for cache metadata
|
|
|
|
class Metadata
|
|
|
|
VALID_BACKING_RESOURCES = [:cpu, :database, :gitaly, :memory, :unknown].freeze
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
# @param cache_identifier [String] defines the location of the cache definition
|
|
|
|
# Example: "ProtectedBranches::CacheService#fetch"
|
|
|
|
# @param feature_category [Symbol] name of the feature category (from config/feature_categories.yml)
|
|
|
|
# @param backing_resource [Symbol] most affected resource by cache generation (full list: VALID_BACKING_RESOURCES)
|
|
|
|
# @return [Gitlab::Cache::Metadata]
|
2023-04-23 21:23:45 +05:30
|
|
|
def initialize(
|
|
|
|
cache_identifier:,
|
|
|
|
feature_category:,
|
2023-05-27 22:25:52 +05:30
|
|
|
backing_resource: Client::DEFAULT_BACKING_RESOURCE
|
2023-04-23 21:23:45 +05:30
|
|
|
)
|
|
|
|
@cache_identifier = cache_identifier
|
|
|
|
@feature_category = Gitlab::FeatureCategories.default.get!(feature_category)
|
|
|
|
@backing_resource = fetch_backing_resource!(backing_resource)
|
|
|
|
end
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
attr_reader :cache_identifier, :feature_category, :backing_resource
|
2023-04-23 21:23:45 +05:30
|
|
|
|
|
|
|
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?
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
Client::DEFAULT_BACKING_RESOURCE
|
2023-04-23 21:23:45 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|