diff options
author | Rémy Coutable <remy@rymai.me> | 2019-07-02 10:10:12 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2019-07-02 10:10:12 +0000 |
commit | 769a9c300a7473dad9c68e8c0448013f803b496a (patch) | |
tree | 5d4a74fefda8f0bb0424be3cc7f4cfd1c0d1bc6a /lib | |
parent | 29b8830bf8ab7cfe37bc0f41066400509fff519f (diff) | |
parent | 618fbde2b7934ad53e585820ee8adb562a837d7f (diff) | |
download | gitlab-ce-769a9c300a7473dad9c68e8c0448013f803b496a.tar.gz |
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.rb | 15 |
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 |