debian-mirror-gitlab/lib/gitlab/reactive_cache_set_cache.rb

33 lines
727 B
Ruby
Raw Normal View History

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 cache_key(key)
2021-09-04 01:27:46 +05:30
"#{cache_namespace}:#{key}:set"
end
def new_cache_key(key)
super(key)
2020-04-08 14:13:33 +05:30
end
def clear_cache!(key)
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)
redis.pipelined do
2020-10-24 23:57:45 +05:30
keys.each_slice(1000) { |subset| redis.unlink(*subset) }
2020-04-08 14:13:33 +05:30
end
end
end
end
end