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

19 files changed

+31
-32
lines changed

README.md

+4-4
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

+1-1
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

+1-1
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

lib/solid_cache/engine.rb

+7-4
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

+1-5
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.

test/lib/generators/solid_cache/solid_cache/install_generator_test.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class SolidCache::InstallGeneratorTest < Rails::Generators::TestCase
1818

1919
test "generator updates environment config" do
2020
run_generator
21-
assert_file "#{destination_root}/config/solid_cache.yml", expected_solid_cache_config
21+
assert_file "#{destination_root}/config/cache.yml", expected_cache_config
2222
assert_file "#{destination_root}/db/cache_schema.rb"
2323
assert_file "#{destination_root}/config/environments/development.rb", /config.cache_store = :memory_store\n/
2424
assert_file "#{destination_root}/config/environments/development.rb", /config.cache_store = :null_store\n/
@@ -27,7 +27,7 @@ class SolidCache::InstallGeneratorTest < Rails::Generators::TestCase
2727
end
2828

2929
private
30-
def expected_solid_cache_config
30+
def expected_cache_config
3131
<<~YAML
3232
default: &default
3333
store_options:

test/models/solid_cache/record_test.rb

+9-9
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@
44

55
module SolidCache
66
class RecordTest < ActiveSupport::TestCase
7-
SINGLE_DB_CONFIGS = [ "config/solid_cache_database.yml", "config/solid_cache_unprepared_statements.yml" ]
7+
SINGLE_DB_CONFIGS = [ "config/cache_database.yml", "config/cache_unprepared_statements.yml" ]
88
MULTI_DB_CONFIGS = [
9-
"config/solid_cache_connects_to.yml",
10-
"config/solid_cache_encrypted.yml",
11-
"config/solid_cache_encrypted_custom.yml",
12-
"config/solid_cache_shards.yml",
9+
"config/cache_connects_to.yml",
10+
"config/cache_encrypted.yml",
11+
"config/cache_encrypted_custom.yml",
12+
"config/cache_shards.yml",
1313
nil
1414
]
1515

1616
test "each_shard" do
1717
shards = SolidCache::Record.each_shard.map { SolidCache::Record.current_shard }
1818
case ENV["SOLID_CACHE_CONFIG"]
19-
when "config/solid_cache_no_database.yml"
19+
when "config/cache_no_database.yml"
2020
assert_equal [ :default ], shards
21-
when "config/solid_cache_database.yml"
21+
when "config/cache_database.yml"
2222
assert_equal [ :primary ], shards
23-
when "config/solid_cache_unprepared_statements.yml"
23+
when "config/cache_unprepared_statements.yml"
2424
assert_equal [ :primary_unprepared_statements ], shards
2525
when *MULTI_DB_CONFIGS
2626
assert_equal [ :primary_shard_one, :primary_shard_two, :secondary_shard_one, :secondary_shard_two ], shards
@@ -32,7 +32,7 @@ class RecordTest < ActiveSupport::TestCase
3232
test "each_shard uses the default role" do
3333
role = ActiveRecord::Base.connected_to(role: :reading) { SolidCache::Record.each_shard.map { SolidCache::Record.current_role } }
3434
case ENV["SOLID_CACHE_CONFIG"]
35-
when "config/solid_cache_no_database.yml"
35+
when "config/cache_no_database.yml"
3636
assert_equal [ :reading ], role
3737
when *SINGLE_DB_CONFIGS
3838
assert_equal [ :writing ], role

test/test_helper.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ def second_shard_key
8282
end
8383

8484
def single_database?
85-
[ "config/solid_cache_database.yml", "config/solid_cache_no_database.yml", "config/solid_cache_unprepared_statements.yml" ].include?(ENV["SOLID_CACHE_CONFIG"])
85+
[ "config/cache_database.yml", "config/cache_no_database.yml", "config/cache_unprepared_statements.yml" ].include?(ENV["SOLID_CACHE_CONFIG"])
8686
end
8787

8888
def default_database?
89-
ENV["SOLID_CACHE_CONFIG"] == "config/solid_cache_no_database.yml"
89+
ENV["SOLID_CACHE_CONFIG"] == "config/cache_no_database.yml"
9090
end
9191

9292
def shard_keys(cache, shard)

test/unit/encryption_test.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ class SolidCache::EncryptionTest < ActiveSupport::TestCase
99
end
1010

1111
test "not encrypted" do
12-
skip if ENV["SOLID_CACHE_CONFIG"] =~ /config\/solid_cache_encrypted.*\.yml/
12+
skip if ENV["SOLID_CACHE_CONFIG"] =~ /config\/cache_encrypted.*\.yml/
1313

1414
@cache.write(@shard_key, "value")
1515
assert_not_nil first_value
1616
assert_equal raw_first_value, first_value
1717
end
1818

1919
test "encrypted with defaults" do
20-
skip unless ENV["SOLID_CACHE_CONFIG"] == "config/solid_cache_encrypted.yml"
20+
skip unless ENV["SOLID_CACHE_CONFIG"] == "config/cache_encrypted.yml"
2121

2222
@cache.write(@shard_key, "value")
2323
assert_not_nil first_value
@@ -28,7 +28,7 @@ class SolidCache::EncryptionTest < ActiveSupport::TestCase
2828
end
2929

3030
test "encrypted with custom settings" do
31-
skip unless ENV["SOLID_CACHE_CONFIG"] == "config/solid_cache_encrypted_custom.yml"
31+
skip unless ENV["SOLID_CACHE_CONFIG"] == "config/cache_encrypted_custom.yml"
3232

3333
@cache.write(@shard_key, "value")
3434
assert_not_nil first_value

test/unit/stats_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class SolidCache::StatsTest < ActiveSupport::TestCase
1111
end
1212

1313
def test_stats_with_entries_no_shards
14-
skip unless ENV["SOLID_CACHE_CONFIG"] == "config/solid_cache_no_database.yml"
14+
skip unless ENV["SOLID_CACHE_CONFIG"] == "config/cache_no_database.yml"
1515

1616
@cache = lookup_store(expiry_batch_size: 2, max_age: 2.weeks.to_i, max_entries: 1000)
1717

0 commit comments

Comments
 (0)