Class: Gitlab::EtagCaching::Store

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/etag_caching/store.rb

Constant Summary collapse

InvalidKeyError =
Class.new(StandardError)
EXPIRY_TIME =
20.minutes
SHARED_STATE_NAMESPACE =
'etag:'

Instance Method Summary collapse

Instance Method Details

#get(key) ⇒ Object


11
12
13
# File 'lib/gitlab/etag_caching/store.rb', line 11

def get(key)
  Gitlab::Redis::SharedState.with { |redis| redis.get(redis_shared_state_key(key)) }
end

#touch(*keys, only_if_missing: false) ⇒ Object


15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/gitlab/etag_caching/store.rb', line 15

def touch(*keys, only_if_missing: false)
  etags = keys.map { generate_etag }

  Gitlab::Redis::SharedState.with do |redis|
    redis.pipelined do
      keys.each_with_index do |key, i|
        redis.set(redis_shared_state_key(key), etags[i], ex: EXPIRY_TIME, nx: only_if_missing)
      end
    end
  end

  keys.size > 1 ? etags : etags.first
end