diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-25 00:14:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-25 00:14:06 +0300 |
commit | 8e73c80c681d8b02633ae25dbd642ecff4864511 (patch) | |
tree | 5d33c6c8cd78c596f80997864b3558edf430b666 /lib/gitlab/process_memory_cache | |
parent | fdc98c3e3cfdca66222044fc6aa195011d227ee2 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/process_memory_cache')
-rw-r--r-- | lib/gitlab/process_memory_cache/helper.rb | 51 |
1 files changed, 0 insertions, 51 deletions
diff --git a/lib/gitlab/process_memory_cache/helper.rb b/lib/gitlab/process_memory_cache/helper.rb deleted file mode 100644 index ee4b81a9a19..00000000000 --- a/lib/gitlab/process_memory_cache/helper.rb +++ /dev/null @@ -1,51 +0,0 @@ -# frozen_string_literal: true - -module Gitlab - class ProcessMemoryCache - module Helper - def fetch_memory_cache(key, &payload) - cache = cache_backend.read(key) - - if cache && !stale_cache?(key, cache) - cache[:data] - else - store_cache(key, &payload) - end - end - - def invalidate_memory_cache(key) - touch_cache_timestamp(key) - end - - private - - def touch_cache_timestamp(key, time = Time.current.to_f) - shared_backend.write(key, time) - end - - def stale_cache?(key, cache_info) - shared_timestamp = shared_backend.read(key) - return true unless shared_timestamp - - shared_timestamp.to_f > cache_info[:cached_at].to_f - end - - def store_cache(key) - data = yield - time = Time.current.to_f - - cache_backend.write(key, data: data, cached_at: time) - touch_cache_timestamp(key, time) - data - end - - def shared_backend - Rails.cache - end - - def cache_backend - ::Gitlab::ProcessMemoryCache.cache_backend - end - end - end -end |