Class: Gitlab::ReactiveCacheSetCache

Inherits:
SetCache
  • Object
show all
Defined in:
lib/gitlab/reactive_cache_set_cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from SetCache

#exist?, #expire, #include?, #read, #ttl, #write

Constructor Details

#initialize(expires_in: 10.minutes) ⇒ ReactiveCacheSetCache

Returns a new instance of ReactiveCacheSetCache.


9
10
11
# File 'lib/gitlab/reactive_cache_set_cache.rb', line 9

def initialize(expires_in: 10.minutes)
  @expires_in = expires_in
end

Instance Attribute Details

#expires_inObject (readonly)

Returns the value of attribute expires_in


7
8
9
# File 'lib/gitlab/reactive_cache_set_cache.rb', line 7

def expires_in
  @expires_in
end

Instance Method Details

#cache_key(key) ⇒ Object


13
14
15
# File 'lib/gitlab/reactive_cache_set_cache.rb', line 13

def cache_key(key)
  "#{cache_type}:#{key}:set"
end

#clear_cache!(key) ⇒ Object


17
18
19
20
21
22
23
24
25
26
# File 'lib/gitlab/reactive_cache_set_cache.rb', line 17

def clear_cache!(key)
  with do |redis|
    keys = read(key).map { |value| "#{cache_type}:#{value}" }
    keys << cache_key(key)

    redis.pipelined do
      keys.each_slice(1000) { |subset| redis.unlink(*subset) }
    end
  end
end