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:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-24 12:08:51 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-24 12:08:51 +0300
commit38149afcf95e7669a7a99828c579d185b70c04dc (patch)
tree3a90504bd926407c0cc60f44e20dba08217b928b /lib/gitlab/set_cache.rb
parentbe660fe1d28a65ad61be24c71e66ae90f6488dc4 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/set_cache.rb')
-rw-r--r--lib/gitlab/set_cache.rb55
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/gitlab/set_cache.rb b/lib/gitlab/set_cache.rb
new file mode 100644
index 00000000000..0927a3e64bb
--- /dev/null
+++ b/lib/gitlab/set_cache.rb
@@ -0,0 +1,55 @@
+# 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 SetCache
+ attr_reader :expires_in
+
+ def initialize(expires_in: 2.weeks)
+ @expires_in = expires_in
+ end
+
+ def cache_key(key)
+ "#{key}:set"
+ end
+
+ def expire(key)
+ with { |redis| redis.del(cache_key(key)) }
+ end
+
+ def exist?(key)
+ with { |redis| redis.exists(cache_key(key)) }
+ end
+
+ def write(key, value)
+ with do |redis|
+ redis.pipelined do
+ redis.sadd(cache_key(key), value)
+
+ redis.expire(cache_key(key), expires_in)
+ end
+ end
+
+ value
+ end
+
+ def read(key)
+ with { |redis| redis.smembers(cache_key(key)) }
+ end
+
+ def include?(key, value)
+ with { |redis| redis.sismember(cache_key(key), value) }
+ end
+
+ def ttl(key)
+ with { |redis| redis.ttl(cache_key(key)) }
+ end
+
+ private
+
+ def with(&blk)
+ Gitlab::Redis::Cache.with(&blk) # rubocop:disable CodeReuse/ActiveRecord
+ end
+ end
+end