From db81eeaa41813d5f562ea71f5e205f5cde4b7b73 Mon Sep 17 00:00:00 2001 From: takahashim Date: Wed, 24 Jul 2024 20:30:06 +0900 Subject: [PATCH] use redis for cache and session store --- config/environments/development.rb | 6 +++++- config/environments/production.rb | 1 + config/initializers/session_store.rb | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 config/initializers/session_store.rb diff --git a/config/environments/development.rb b/config/environments/development.rb index bcc255982e..3cbfd12b71 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -19,7 +19,11 @@ if Rails.root.join("tmp/caching-dev.txt").exist? config.action_controller.perform_caching = true - config.cache_store = :memory_store + if ENV["REDIS_CACHE_URL"] # rubocop:disable Style/ConditionalAssignment + config.cache_store = :redis_cache_store, { url: ENV.fetch("REDIS_CACHE_URL", nil) } + else + config.cache_store = :memory_store + end config.public_file_server.headers = { "Cache-Control" => "public, max-age=#{2.days.to_i}" } diff --git a/config/environments/production.rb b/config/environments/production.rb index 37dd365d10..6c1f2f8fb5 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -51,6 +51,7 @@ # Use a different cache store in production. # config.cache_store = :mem_cache_store + config.cache_store = :redis_cache_store, { url: ENV.fetch("REDIS_CACHE_URL", nil) } # Use a real queuing backend for Active Job (and separate queues per environment) # config.active_job.queue_adapter = :resque diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb new file mode 100644 index 0000000000..efcb38536e --- /dev/null +++ b/config/initializers/session_store.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +Rails.application.config.to_prepare do + Rails.application.config.session_store :cache_store if ENV["REDIS_CACHE_URL"] +end