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
path: root/lib
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2019-07-02 13:10:12 +0300
committerRémy Coutable <remy@rymai.me>2019-07-02 13:10:12 +0300
commit769a9c300a7473dad9c68e8c0448013f803b496a (patch)
tree5d4a74fefda8f0bb0424be3cc7f4cfd1c0d1bc6a /lib
parent29b8830bf8ab7cfe37bc0f41066400509fff519f (diff)
parent618fbde2b7934ad53e585820ee8adb562a837d7f (diff)
Merge branch 'sh-add-thread-memory-cache' into 'master'
Add a memory cache local to the thread to reduce Redis load Closes #63977 See merge request gitlab-org/gitlab-ce!30233
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/thread_memory_cache.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/gitlab/thread_memory_cache.rb b/lib/gitlab/thread_memory_cache.rb
new file mode 100644
index 00000000000..7f363dc7feb
--- /dev/null
+++ b/lib/gitlab/thread_memory_cache.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+module Gitlab
+ class ThreadMemoryCache
+ THREAD_KEY = :thread_memory_cache
+
+ def self.cache_backend
+ # Note ActiveSupport::Cache::MemoryStore is thread-safe. Since
+ # each backend is local per thread we probably don't need to worry
+ # about synchronizing access, but this is a drop-in replacement
+ # for ActiveSupport::Cache::RedisStore.
+ Thread.current[THREAD_KEY] ||= ActiveSupport::Cache::MemoryStore.new
+ end
+ end
+end