Skip to content

Conversation

@orbanbotond
Copy link
Contributor

@orbanbotond orbanbotond commented Sep 9, 2025

Fix #278

The problem:
When we run the bundle exec rails solid_cache:install, it generated a cache.yml file which contains the reference to the cache database only for production mode.
(Personal Note: As I was testing the cache in development, I was expecting that the generated file would be perfect for all environments. Then I would turn on the caching for the development environment in the development.rb by config.cache_store = :solid_cache_store if I wanted to. But I was surprised. My eyes just jumped over the missing database:... part in the cache.yml file, so I spent about 20 minutes figuring out what was wrong. If we multiply that 20 minutes by 10000 devs who are struggling, then that is a lot of lost hours ~3300)

The solution:
Generate a ready-to-use cache file.

This decision is up to you (37signal) guys :) I just want to be helpful.

Some other guys were also struggling with this issue:
https://www.reddit.com/r/rails/comments/1gws1fp/help_needed_with_solid_cache/

@AliSepehri
Copy link

I agree, not having solid_cache setup for development is confusing. But this PR changes requires also a change in Rails repo to consider cache in database.yml file otherwise it will fail by default.

@djmb
Copy link
Collaborator

djmb commented Nov 6, 2025

Thanks for the PR @orbanbotond!

As @AliSepehri says we'd need to change the default database.yml in Rails for this to work out of the box. But I don't think that's likely to happen - the default behavior is to stick to an in memory database that works out of the box without having to update the schema.

But I think this change is still useful - it means that when you set config.cache_store = :solid_cache_store in development or test you get a much more useful error message:

>> Rails.cache.write("1", "1")
(dummy-app):1:in '<main>': The `cache` database is not configured for the `development` environment. (ActiveRecord::AdapterNotSpecified)

  Available database configurations are:

  default
development
test
production: primary, cache, queue, cable

namespace: <%%= Rails.env %>

development:
database: <%= ENV.fetch("DATABASE", "cache") %>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should be defaulting to the DATABASE value. The cache is expected to use a different database to the app.

I think we should just have database: cache and move it up to the defaults so we don't need to set it individually for development/test/production.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry <%= ENV.fetch("DATABASE", "cache") %> is what we want - this is the template not the final output!

@djmb djmb merged commit fb7debd into rails:main Nov 6, 2025
40 checks passed
@jeromedalbert
Copy link

jeromedalbert commented Nov 8, 2025

As @AliSepehri says we'd need to change the default database.yml in Rails for this to work out of the box. But I don't think that's likely to happen - the default behavior is to stick to an in memory database that works out of the box without having to update the schema.

It does not work out of the box in CI=true Rails test environments that eager load. This PR, included in v1.0.9, is currently making all new Rails apps fail on CI if they have any tests to run. Not sure if this needs a revert and re-release until the default database.yml is changed in a future Rails version, or if some better approach is needed.

See #291 for details with repro steps.

@djmb
Copy link
Collaborator

djmb commented Nov 8, 2025

Thanks @jeromedalbert, I'll revert and release 1.0.10 for now and take a closer look next week

@jeromedalbert
Copy link

Thank you so much for the extremely quick response @djmb! And sorry for being a Debbie Downer. 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

As I run bin/rails solid_cache:install it generates a cache.yml which doesn't contain a reference to a database for the dev mode.

4 participants