From d7304ea5ac321a18deed47bf2b65a0a8c9cb4316 Mon Sep 17 00:00:00 2001 From: Trevor Turk Date: Tue, 12 Aug 2025 13:52:02 -0500 Subject: [PATCH 1/2] Add single database configuration section Similar to solid_queue, this documents how to configure Solid Cache to use a single database instead of separate databases for the app and cache. --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 3a8174c..4d84cd2 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,16 @@ If `connects_to` is set, it will be passed directly. If none of these are set, Solid Cache will use the `ActiveRecord::Base` connection pool. This means that cache reads and writes will be part of any wrapping database transaction. +### Single database configuration + +Running Solid Cache in a separate database is recommended, but it's also possible to use one single database for both the app and the cache. Follow these steps: + +1. Copy the contents of `db/cache_schema.rb` into a normal migration and delete `db/cache_schema.rb` +2. Remove the `database: cache` line from `config/cache.yml` in the production section +3. Migrate your database. You are ready to run `bin/rails server` + +You won't have multiple databases, so `database.yml` doesn't need to have primary and cache database. + ### Engine configuration There are five options that can be set on the engine: From c95097bee1d7e8df69b5e3f3bee295def94b2217 Mon Sep 17 00:00:00 2001 From: Trevor Turk Date: Tue, 7 Apr 2026 09:19:43 -0500 Subject: [PATCH 2/2] Clarify single-database setup with separate cache pool --- README.md | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4d84cd2..6c06a9d 100644 --- a/README.md +++ b/README.md @@ -98,13 +98,27 @@ If none of these are set, Solid Cache will use the `ActiveRecord::Base` connecti ### Single database configuration -Running Solid Cache in a separate database is recommended, but it's also possible to use one single database for both the app and the cache. Follow these steps: +Running Solid Cache in a separate database is recommended, but for PostgreSQL/MySQL/Trilogy you can use a single physical database and still keep separate connection pools for app and cache traffic. -1. Copy the contents of `db/cache_schema.rb` into a normal migration and delete `db/cache_schema.rb` -2. Remove the `database: cache` line from `config/cache.yml` in the production section -3. Migrate your database. You are ready to run `bin/rails server` +1. Move the schema from `db/cache_schema.rb` (or `db/cache_structure.sql`) into a normal app migration, then delete the cache schema file +2. Keep `database: cache` in `config/cache.yml` +3. Point `primary` and `cache` at the same database in `config/database.yml`, and disable database tasks for `cache`: -You won't have multiple databases, so `database.yml` doesn't need to have primary and cache database. +```yaml +production: + primary: &primary_production + <<: *default + database: app_production + username: app + password: <%= ENV["APP_DATABASE_PASSWORD"] %> + cache: + <<: *primary_production + database_tasks: false +``` + +4. Run `bin/rails db:migrate` + +Do not use this setup with SQLite. SQLite allows only one write transaction at a time, so separate pools to the same database can block each other. For SQLite, use a separate cache database. ### Engine configuration