Skip to content

Commit 4a7e97d

Browse files
committed
Default to cache.yml instead of solid_cache.yml
We'll fall back to the old filename if cache.yml doesn't exist.
1 parent a4da863 commit 4a7e97d

File tree

19 files changed

+31
-32
lines changed

19 files changed

+31
-32
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Solid Cache is configured by default in new Rails 8 applications. But if you're
99
1. `bundle add solid_cache`
1010
2. `bin/rails solid_cache:install`
1111

12-
This will configure Solid Cache as the production cache store, create `config/solid_cache.yml`, and create `db/cache_schema.rb`.
12+
This will configure Solid Cache as the production cache store, create `config/cache.yml`, and create `db/cache_schema.rb`.
1313

1414
You will then have to add the configuration for the queue database in `config/database.yml`. If you're using sqlite, it'll look like this:
1515

@@ -43,7 +43,7 @@ Then run `db:prepare` in production to ensure the database is created and the sc
4343

4444
## Configuration
4545

46-
Configuration will be read from `config/solid_cache.yml`. You can change the location of the config file by setting the `SOLID_CACHE_CONFIG` env variable.
46+
Configuration will be read from `config/cache.yml` or `config/solid_cache.yml`. You can change the location of the config file by setting the `SOLID_CACHE_CONFIG` env variable.
4747

4848
The format of the file is:
4949

@@ -169,7 +169,7 @@ production:
169169
```
170170

171171
```yaml
172-
# config/solid_cache.yml
172+
# config/cache.yml
173173
production:
174174
databases: [cache_shard1, cache_shard2, cache_shard3]
175175
```
@@ -179,7 +179,7 @@ production:
179179
To encrypt the cache values, you can add the encrypt property.
180180

181181
```yaml
182-
# config/solid_cache.yml
182+
# config/cache.yml
183183
production:
184184
encrypt: true
185185
```

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ configs.each do |config|
4444
if config == :default
4545
sh("bin/rails test")
4646
else
47-
sh("SOLID_CACHE_CONFIG=config/solid_cache_#{config}.yml bin/rails test")
47+
sh("SOLID_CACHE_CONFIG=config/cache_#{config}.yml bin/rails test")
4848
end
4949
end
5050
end

lib/generators/solid_cache/install/install_generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class SolidCache::InstallGenerator < Rails::Generators::Base
44
source_root File.expand_path("templates", __dir__)
55

66
def copy_files
7-
template "config/solid_cache.yml"
7+
template "config/cache.yml"
88
template "db/cache_schema.rb"
99
end
1010

File renamed without changes.

lib/solid_cache/engine.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ class Engine < ::Rails::Engine
1010
config.solid_cache = ActiveSupport::OrderedOptions.new
1111

1212
initializer "solid_cache.config", before: :initialize_cache do |app|
13-
app.paths.add "config/solid_cache", with: ENV["SOLID_CACHE_CONFIG"] || "config/solid_cache.yml"
13+
config_paths = %w[config/cache config/solid_cache]
1414

15-
options = {}
16-
if (config_path = Pathname.new(app.config.paths["config/solid_cache"].first)).exist?
17-
options = app.config_for(config_path).to_h.deep_symbolize_keys
15+
config_paths.each do |path|
16+
app.paths.add path, with: ENV["SOLID_CACHE_CONFIG"] || "#{path}.yml"
1817
end
1918

19+
config_pathname = config_paths.map { |path| Pathname.new(app.config.paths[path].first) }.find(&:exist?)
20+
21+
options = config_pathname ? app.config_for(config_pathname).to_h.deep_symbolize_keys : {}
22+
2023
options[:connects_to] = config.solid_cache.connects_to if config.solid_cache.connects_to
2124
options[:size_estimate_samples] = config.solid_cache.size_estimate_samples if config.solid_cache.size_estimate_samples
2225
options[:encrypt] = config.solid_cache.encrypt if config.solid_cache.encrypt

test/dummy/config/application.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,11 @@ class Application < Rails::Application
1818

1919
config.active_record.encryption.key_provider = ActiveRecord::Encryption::EnvelopeEncryptionKeyProvider.new
2020

21-
if ENV["SOLID_CACHE_CONFIG"] == "config/solid_cache_encrypted_custom.yml"
21+
if ENV["SOLID_CACHE_CONFIG"] == "config/cache_encrypted_custom.yml"
2222
config.solid_cache.encryption_context_properties = {
2323
encryptor: ActiveRecord::Encryption::Encryptor.new,
2424
message_serializer: ActiveRecord::Encryption::MessageSerializer.new
2525
}
2626
end
27-
28-
initializer :custom_solid_cache_yml, before: :solid_cache do |app|
29-
app.paths.add "config/solid_cache", with: ENV["SOLID_CACHE_CONFIG_PATH"]
30-
end
3127
end
3228
end
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)