2020-04-08 14:13:33 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Interface to the Redis-backed cache store to keep track of complete cache keys
|
|
|
|
# for a ReactiveCache resource.
|
|
|
|
module Gitlab
|
|
|
|
class ReactiveCacheSetCache < Gitlab::SetCache
|
|
|
|
attr_reader :expires_in
|
|
|
|
|
|
|
|
def initialize(expires_in: 10.minutes)
|
|
|
|
@expires_in = expires_in
|
|
|
|
end
|
|
|
|
|
|
|
|
def clear_cache!(key)
|
2023-07-09 08:55:56 +05:30
|
|
|
use_pipeline = ::Feature.enabled?(:use_pipeline_over_multikey)
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
with do |redis|
|
2021-09-04 01:27:46 +05:30
|
|
|
keys = read(key).map { |value| "#{cache_namespace}:#{value}" }
|
2020-04-08 14:13:33 +05:30
|
|
|
keys << cache_key(key)
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
Gitlab::Instrumentation::RedisClusterValidator.allow_cross_slot_commands do
|
|
|
|
redis.pipelined do |pipeline|
|
2023-07-09 08:55:56 +05:30
|
|
|
if use_pipeline
|
|
|
|
keys.each { |key| pipeline.unlink(key) }
|
|
|
|
else
|
|
|
|
keys.each_slice(1000) { |subset| pipeline.unlink(*subset) }
|
|
|
|
end
|
2022-10-11 01:57:18 +05:30
|
|
|
end
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|