diff --git a/Gemfile b/Gemfile index 8077ea4e..abf9e2e9 100644 --- a/Gemfile +++ b/Gemfile @@ -60,6 +60,7 @@ gem "sanitize" gem "twitter-text" +gem "connection_pool" gem "redis" gem "fake_email_validator" diff --git a/Gemfile.lock b/Gemfile.lock index 424c92b5..96a87385 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -489,6 +489,7 @@ DEPENDENCIES carrierwave (~> 2.0) carrierwave_backgrounder! colorize + connection_pool cssbundling-rails (~> 1.1) database_cleaner devise (~> 4.0) diff --git a/config/environments/production.rb b/config/environments/production.rb index 3ae984d5..6fe7f142 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -54,7 +54,19 @@ Rails.application.configure do config.lograge.enabled = true # Use a different cache store in production. - # config.cache_store = :mem_cache_store + cache_redis_url = ENV.fetch("CACHE_REDIS_URL") { nil } + if cache_redis_url.present? + config.cache_store = :redis_cache_store, { + url: cache_redis_url, + pool_size: ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i, + pool_timeout: ENV.fetch("CACHE_REDIS_TIMEOUT") { 5 }, + error_handler: -> (method:, returning:, exception:) { + # Report errors to Sentry as warnings + Sentry.capture_exception exception, level: 'warning', + tags: { method: method, returning: returning } + }, + } + end # Use a real queuing backend for Active Job (and separate queues per environment) # config.active_job.queue_adapter = :resque