Skip to content

Introduce wrapper for Rails.cache to handle Redis cache

Proposal

Create a wrapper for Rails.cache that will:

  1. create Redis keys in the structured format (see here)
  2. 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