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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

36 lines
1 KiB
Ruby
Raw Normal View History

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
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