2020-02-24 04:08:51 -05:00
|
|
|
# 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
|
|
|
|
|
2021-06-28 11:08:03 -04:00
|
|
|
# NOTE Remove as part of #331319
|
|
|
|
def old_cache_key(key)
|
2021-05-25 11:10:33 -04:00
|
|
|
"#{cache_namespace}:#{key}:set"
|
|
|
|
end
|
|
|
|
|
2021-06-28 11:08:03 -04:00
|
|
|
def cache_key(key)
|
2021-05-25 11:10:33 -04:00
|
|
|
super(key)
|
2020-02-26 10:08:56 -05:00
|
|
|
end
|
|
|
|
|
2020-02-24 04:08:51 -05:00
|
|
|
def clear_cache!(key)
|
|
|
|
with do |redis|
|
2021-05-25 11:10:33 -04:00
|
|
|
keys = read(key).map { |value| "#{cache_namespace}:#{value}" }
|
2020-02-24 04:08:51 -05:00
|
|
|
keys << cache_key(key)
|
|
|
|
|
|
|
|
redis.pipelined do
|
2020-08-17 14:10:01 -04:00
|
|
|
keys.each_slice(1000) { |subset| redis.unlink(*subset) }
|
2020-02-24 04:08:51 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|