From e93b693f717865f876e126ca367d0a63826652e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 28 Sep 2022 13:28:31 +0200 Subject: [PATCH] Use different cache namespaces for different tenants Since records in different tenants can have the same ID, they can share the same `cache_key`, and so we need a namespace to differentiate them. Without them, records from one tenant could expire the cache of a record from another tenant. --- config/environments/development.rb | 2 +- config/environments/production.rb | 2 +- config/environments/staging.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/environments/development.rb b/config/environments/development.rb index 925734721..13479dc34 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -18,7 +18,7 @@ Rails.application.configure do config.action_controller.perform_caching = true config.action_controller.enable_fragment_cache_logging = true - config.cache_store = :memory_store + config.cache_store = :memory_store, { namespace: proc { Tenant.current_schema }} 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 2eb1a3cdd..47c8ac22a 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -58,7 +58,7 @@ Rails.application.configure do config.log_tags = [:request_id] # Use a different cache store in production. - config.cache_store = :mem_cache_store + config.cache_store = :mem_cache_store, { namespace: proc { Tenant.current_schema }} # Use a real queuing backend for Active Job (and separate queues per environment). # config.active_job.queue_adapter = :resque diff --git a/config/environments/staging.rb b/config/environments/staging.rb index 1d947e064..87c57f36d 100644 --- a/config/environments/staging.rb +++ b/config/environments/staging.rb @@ -58,7 +58,7 @@ Rails.application.configure do config.log_tags = [:request_id] # Use a different cache store in production. - config.cache_store = :mem_cache_store + config.cache_store = :mem_cache_store, { namespace: proc { Tenant.current_schema }} # Use a real queuing backend for Active Job (and separate queues per environment). # config.active_job.queue_adapter = :resque