Commit d1fbc9e1 authored by Nick Thomas's avatar Nick Thomas

Merge branch '331319-set-cache-gitlab-namespce-read-write' into 'master'

Enable writing set cache keys in new format

See merge request gitlab-org/gitlab!64756
parents 7308f215 94aa74cf
......@@ -10,11 +10,12 @@ module Gitlab
@expires_in = expires_in
end
def cache_key(key)
# NOTE Remove as part of #331319
def old_cache_key(key)
"#{cache_namespace}:#{key}:set"
end
def new_cache_key(key)
def cache_key(key)
super(key)
end
......
......@@ -13,12 +13,12 @@ module Gitlab
@expires_in = expires_in
end
def cache_key(type)
# NOTE Remove as part of #331319
def old_cache_key(type)
"#{type}:#{namespace}:set"
end
# NOTE Remove as part of #331319
def new_cache_key(type)
def cache_key(type)
super("#{type}:#{namespace}")
end
......
......@@ -10,12 +10,12 @@ module Gitlab
@expires_in = expires_in
end
def cache_key(key)
# NOTE Remove as part of https://gitlab.com/gitlab-org/gitlab/-/issues/331319
def old_cache_key(key)
"#{key}:set"
end
# NOTE Remove as part of https://gitlab.com/gitlab-org/gitlab/-/issues/331319
def new_cache_key(key)
def cache_key(key)
"#{cache_namespace}:#{key}:set"
end
......@@ -25,7 +25,7 @@ module Gitlab
with do |redis|
keys_to_expire = keys.map { |key| cache_key(key) }
keys_to_expire += keys.map { |key| new_cache_key(key) } # NOTE Remove as part of #331319
keys_to_expire += keys.map { |key| old_cache_key(key) } # NOTE Remove as part of #331319
Gitlab::Instrumentation::RedisClusterValidator.allow_cross_slot_commands do
redis.unlink(*keys_to_expire)
......
......@@ -15,7 +15,7 @@ RSpec.describe Gitlab::RepositorySetCache, :clean_gitlab_redis_cache do
shared_examples 'cache_key examples' do
it 'includes the namespace' do
is_expected.to eq("foo:#{namespace}:set")
is_expected.to eq("#{gitlab_cache_namespace}:foo:#{namespace}:set")
end
context 'with a given namespace' do
......@@ -23,7 +23,7 @@ RSpec.describe Gitlab::RepositorySetCache, :clean_gitlab_redis_cache do
let(:cache) { described_class.new(repository, extra_namespace: extra_namespace) }
it 'includes the full namespace' do
is_expected.to eq("foo:#{namespace}:#{extra_namespace}:set")
is_expected.to eq("#{gitlab_cache_namespace}:foo:#{namespace}:#{extra_namespace}:set")
end
end
end
......@@ -60,7 +60,7 @@ RSpec.describe Gitlab::RepositorySetCache, :clean_gitlab_redis_cache do
write_cache
redis_keys = Gitlab::Redis::Cache.with { |redis| redis.scan(0, match: "*") }.last
expect(redis_keys).to include("branch_names:#{namespace}:set")
expect(redis_keys).to include("#{gitlab_cache_namespace}:branch_names:#{namespace}:set")
expect(cache.fetch('branch_names')).to contain_exactly('main')
end
......@@ -95,8 +95,8 @@ RSpec.describe Gitlab::RepositorySetCache, :clean_gitlab_redis_cache do
expect(cache.read(:foo)).to be_empty
end
it 'expires the new key format' do
expect_any_instance_of(Redis).to receive(:unlink).with(cache.cache_key(:foo), cache.new_cache_key(:foo)) # rubocop:disable RSpec/AnyInstanceOf
it 'expires the old key format' do
expect_any_instance_of(Redis).to receive(:unlink).with(cache.cache_key(:foo), cache.old_cache_key(:foo)) # rubocop:disable RSpec/AnyInstanceOf
subject
end
......
......@@ -36,8 +36,6 @@ RSpec.describe 'clearing redis cache', :clean_gitlab_redis_cache, :silence_stdou
let(:cache) { Gitlab::RepositorySetCache.new(repository) }
before do
pending "Enable as part of https://gitlab.com/gitlab-org/gitlab/-/issues/331319"
cache.write(:foo, [:bar])
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment