Commit 94aa74cf authored by Sean Arnold's avatar Sean Arnold

Enable writing set cache keys in new format

- Keep expiry in old format too
parent b9bd0a86
...@@ -10,11 +10,12 @@ module Gitlab ...@@ -10,11 +10,12 @@ module Gitlab
@expires_in = expires_in @expires_in = expires_in
end end
def cache_key(key) # NOTE Remove as part of #331319
def old_cache_key(key)
"#{cache_namespace}:#{key}:set" "#{cache_namespace}:#{key}:set"
end end
def new_cache_key(key) def cache_key(key)
super(key) super(key)
end end
......
...@@ -13,12 +13,12 @@ module Gitlab ...@@ -13,12 +13,12 @@ module Gitlab
@expires_in = expires_in @expires_in = expires_in
end end
def cache_key(type) # NOTE Remove as part of #331319
def old_cache_key(type)
"#{type}:#{namespace}:set" "#{type}:#{namespace}:set"
end end
# NOTE Remove as part of #331319 def cache_key(type)
def new_cache_key(type)
super("#{type}:#{namespace}") super("#{type}:#{namespace}")
end end
......
...@@ -10,12 +10,12 @@ module Gitlab ...@@ -10,12 +10,12 @@ module Gitlab
@expires_in = expires_in @expires_in = expires_in
end 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" "#{key}:set"
end end
# NOTE Remove as part of https://gitlab.com/gitlab-org/gitlab/-/issues/331319 def cache_key(key)
def new_cache_key(key)
"#{cache_namespace}:#{key}:set" "#{cache_namespace}:#{key}:set"
end end
...@@ -25,7 +25,7 @@ module Gitlab ...@@ -25,7 +25,7 @@ module Gitlab
with do |redis| with do |redis|
keys_to_expire = keys.map { |key| cache_key(key) } 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 Gitlab::Instrumentation::RedisClusterValidator.allow_cross_slot_commands do
redis.unlink(*keys_to_expire) redis.unlink(*keys_to_expire)
......
...@@ -15,7 +15,7 @@ RSpec.describe Gitlab::RepositorySetCache, :clean_gitlab_redis_cache do ...@@ -15,7 +15,7 @@ RSpec.describe Gitlab::RepositorySetCache, :clean_gitlab_redis_cache do
shared_examples 'cache_key examples' do shared_examples 'cache_key examples' do
it 'includes the namespace' do it 'includes the namespace' do
is_expected.to eq("foo:#{namespace}:set") is_expected.to eq("#{gitlab_cache_namespace}:foo:#{namespace}:set")
end end
context 'with a given namespace' do context 'with a given namespace' do
...@@ -23,7 +23,7 @@ RSpec.describe Gitlab::RepositorySetCache, :clean_gitlab_redis_cache do ...@@ -23,7 +23,7 @@ RSpec.describe Gitlab::RepositorySetCache, :clean_gitlab_redis_cache do
let(:cache) { described_class.new(repository, extra_namespace: extra_namespace) } let(:cache) { described_class.new(repository, extra_namespace: extra_namespace) }
it 'includes the full namespace' do 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 end
end end
...@@ -60,7 +60,7 @@ RSpec.describe Gitlab::RepositorySetCache, :clean_gitlab_redis_cache do ...@@ -60,7 +60,7 @@ RSpec.describe Gitlab::RepositorySetCache, :clean_gitlab_redis_cache do
write_cache write_cache
redis_keys = Gitlab::Redis::Cache.with { |redis| redis.scan(0, match: "*") }.last 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') expect(cache.fetch('branch_names')).to contain_exactly('main')
end end
...@@ -95,8 +95,8 @@ RSpec.describe Gitlab::RepositorySetCache, :clean_gitlab_redis_cache do ...@@ -95,8 +95,8 @@ RSpec.describe Gitlab::RepositorySetCache, :clean_gitlab_redis_cache do
expect(cache.read(:foo)).to be_empty expect(cache.read(:foo)).to be_empty
end end
it 'expires the new key format' do it 'expires the old 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 expect_any_instance_of(Redis).to receive(:unlink).with(cache.cache_key(:foo), cache.old_cache_key(:foo)) # rubocop:disable RSpec/AnyInstanceOf
subject subject
end end
......
...@@ -36,8 +36,6 @@ RSpec.describe 'clearing redis cache', :clean_gitlab_redis_cache, :silence_stdou ...@@ -36,8 +36,6 @@ RSpec.describe 'clearing redis cache', :clean_gitlab_redis_cache, :silence_stdou
let(:cache) { Gitlab::RepositorySetCache.new(repository) } let(:cache) { Gitlab::RepositorySetCache.new(repository) }
before do before do
pending "Enable as part of https://gitlab.com/gitlab-org/gitlab/-/issues/331319"
cache.write(:foo, [:bar]) cache.write(:foo, [:bar])
end 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