debian-mirror-gitlab/lib/gitlab/redis/cache.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

36 lines
1 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
module Gitlab
module Redis
2023-04-23 21:23:45 +05:30
# Match signature in
# https://github.com/rails/rails/blob/v6.1.7.2/activesupport/lib/active_support/cache/redis_cache_store.rb#L59
ERROR_HANDLER = ->(method:, returning:, exception:) do
Gitlab::ErrorTracking.log_exception(
exception,
method: method,
returning: returning.inspect
)
end
2017-09-10 17:25:29 +05:30
class Cache < ::Gitlab::Redis::Wrapper
2019-12-04 20:38:33 +05:30
CACHE_NAMESPACE = 'cache:gitlab'
2017-09-10 17:25:29 +05:30
2021-11-18 22:05:49 +05:30
# Full list of options:
# https://api.rubyonrails.org/classes/ActiveSupport/Cache/RedisCacheStore.html#method-c-new
def self.active_support_config
{
redis: pool,
compress: Gitlab::Utils.to_boolean(ENV.fetch('ENABLE_REDIS_CACHE_COMPRESSION', '1')),
namespace: CACHE_NAMESPACE,
2023-04-23 21:23:45 +05:30
expires_in: default_ttl_seconds,
error_handler: ::Gitlab::Redis::ERROR_HANDLER
2021-11-18 22:05:49 +05:30
}
2017-09-10 17:25:29 +05:30
end
2023-04-23 21:23:45 +05:30
def self.default_ttl_seconds
ENV.fetch('GITLAB_RAILS_CACHE_DEFAULT_TTL_SECONDS', 8.hours).to_i
end
2017-09-10 17:25:29 +05:30
end
end
end