Introduce wrapper for Rails.cache to handle Redis cache
- Epic: &9313
- Discussion: #378189 (comment 1166190924)
Proposal
Create a wrapper for Rails.cache that will:
- create Redis keys in the structured format (see here)
- auto-initialize metrics for each Redis key (see
Gitlab::Cache::Metrics
)
Before
Rails.cache.fetch('mykey') do
work_hard!
end
After (proposal)
Gitlab::Redis::Cache::Client.new(
cache_identifier: "#{self.class}#fetch",
feature_category: :source_code_management,
backing_resource: :cpu
).fetch('mykey') do
work_hard!
end
This code, will read and if necessary create a new Redis key with new format. Additionally it will record cache generation time and bump hit/miss cache counter.
Edited by Vasilii Iakliushin