Skip to content

Create a wrapper for Rails.cache with metrics support

Vasilii Iakliushin requested to merge 383458_wrapper_for_rails_cache into master

What does this MR do and why?

Contributes to #383458 (closed)

Problem

We don't have hit-rate and time of generation metrics for Redis cache

Solution

Create a in-place replacement for Rails.cache call with metrics integrations

Roadmap

Step MR
Refactor Gitlab::Cache::Metrics !111345 (merged)
Create Gitlab::Cache::Client 👈 this MR

Example

https://gitlab.com/gitlab-org/gitlab/blob/80ff2c3140970dedbae17639c9eea2e086682848/lib/api/files.rb#L52

Before

Rails.cache.fetch("blob_content_sha256:#{user_project.full_path}:#{@blob.id}") do
  @blob.load_all_data!

  Digest::SHA256.hexdigest(@blob.data)
end

After

cache_client = Gitlab::Cache::Client.meta(
  feature_category: :source_code_management,
  cache_identifier: "#{self.class}#content_sha"
)

cache_client.fetch("blob_content_sha256:#{user_project.full_path}:#{@blob.id}") do
  @blob.load_all_data!

  Digest::SHA256.hexdigest(@blob.data)
end

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Vasilii Iakliushin

Merge request reports

Loading