Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/etag_caching/store.rb')
-rw-r--r--lib/gitlab/etag_caching/store.rb12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/gitlab/etag_caching/store.rb b/lib/gitlab/etag_caching/store.rb
index bc97c88ce85..f36a7a0603c 100644
--- a/lib/gitlab/etag_caching/store.rb
+++ b/lib/gitlab/etag_caching/store.rb
@@ -9,15 +9,15 @@ module Gitlab
SHARED_STATE_NAMESPACE = 'etag:'
def get(key)
- Gitlab::Redis::SharedState.with { |redis| redis.get(redis_shared_state_key(key)) }
+ with_redis { |redis| redis.get(redis_shared_state_key(key)) }
end
def touch(*keys, only_if_missing: false)
etags = keys.map { generate_etag }
Gitlab::Instrumentation::RedisClusterValidator.allow_cross_slot_commands do
- Gitlab::Redis::SharedState.with do |redis|
- redis.pipelined do |pipeline|
+ with_redis do |redis|
+ Gitlab::Redis::CrossSlot::Pipeline.new(redis).pipelined do |pipeline|
keys.each_with_index do |key, i|
pipeline.set(redis_shared_state_key(key), etags[i], ex: EXPIRY_TIME, nx: only_if_missing)
end
@@ -30,6 +30,12 @@ module Gitlab
private
+ def with_redis(&blk)
+ # We use multistore as n interweaving double-write will result in n-1 subsequent requests
+ # becoming a cache-miss, however, 2 interweaving .touch will lead to 1 cache miss anyway.
+ Gitlab::Redis::EtagCache.with(&blk) # rubocop:disable CodeReuse/ActiveRecord
+ end
+
def generate_etag
SecureRandom.hex
end