solid_cache 1.0.4 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4166bf227d59acde335e056a12f2a382863fe469fa8417827e19da72bc12fb7b
4
- data.tar.gz: af1066a13d699e9ca3716c7b8b12f0b50e379b5cc5940757f613c51a08b9114a
3
+ metadata.gz: 1cf02364d38d08f18cbe3d9811a7957018ec23ebaf08951c51110204eea237de
4
+ data.tar.gz: c04b221f9c37fdc78f78e07143afe33bc1d346695ef8c910dc986533dd460a38
5
5
  SHA512:
6
- metadata.gz: 8fe05aebd5d0279edb79654b8cd432efc78232d5f998b661d8026b23dcfb7ab73de74c407ce2594a15d01809a377711fb7bb8ffb060823619341ac0020564973
7
- data.tar.gz: 78995f9165d9f0c3da70bfe8499d89cf4fefb17cd7a5c8d0971815e21688ff71303b9da040a301aed7cf6bac46d6a6245c32657d170e4b1631278327715d110f
6
+ metadata.gz: 725fa1c931e54f8aa743aa8311fd05f44fe200904ede83bcb1207377f54926c330abe887a2dfb04c956f703f8e673b38f8af219a31e04c2f1d653cdbe0b980db
7
+ data.tar.gz: 6d793397978b7d1e1797ed4b97726dc25c1e053a8a8dc2aa9b39669bbb79c3a9d7b9d0d676e43bea4f1a401ae7528a1aee34c5985899e96e092b86c1be4c2f0a
data/README.md CHANGED
@@ -8,13 +8,42 @@ Solid Cache is configured by default in new Rails 8 applications. But if you're
8
8
 
9
9
  1. `bundle add solid_cache`
10
10
  2. `bin/rails solid_cache:install`
11
- 3. `bin/rails db:migrate`
12
11
 
13
- This will configure Solid Queue as the production cache store, create `config/solid_cache.yml`, and alter `config/database.yml` to include the new cache database.
12
+ This will configure Solid Cache as the production cache store, create `config/cache.yml`, and create `db/cache_schema.rb`.
13
+
14
+ 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:
15
+
16
+ ```yaml
17
+ production:
18
+ primary:
19
+ <<: *default
20
+ database: storage/production.sqlite3
21
+ cache:
22
+ <<: *default
23
+ database: storage/production_cache.sqlite3
24
+ migrations_paths: db/cache_migrate
25
+ ```
26
+
27
+ ...or if you're using MySQL/PostgreSQL/Trilogy:
28
+
29
+ ```yaml
30
+ production:
31
+ primary: &primary_production
32
+ <<: *default
33
+ database: app_production
34
+ username: app
35
+ password: <%= ENV["APP_DATABASE_PASSWORD"] %>
36
+ cache:
37
+ <<: *primary_production
38
+ database: app_production_cache
39
+ migrations_paths: db/cache_migrate
40
+ ```
41
+
42
+ Then run `db:prepare` in production to ensure the database is created and the schema is loaded.
14
43
 
15
44
  ## Configuration
16
45
 
17
- 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.
18
47
 
19
48
  The format of the file is:
20
49
 
@@ -62,7 +91,7 @@ If none of these are set, Solid Cache will use the `ActiveRecord::Base` connecti
62
91
 
63
92
  ### Engine configuration
64
93
 
65
- There are three options that can be set on the engine:
94
+ There are five options that can be set on the engine:
66
95
 
67
96
  - `executor` - the [Rails executor](https://guides.rubyonrails.org/threading_and_code_execution.html#executor) used to wrap asynchronous operations, defaults to the app executor
68
97
  - `connects_to` - a custom connects to value for the abstract `SolidCache::Record` active record model. Required for sharding and/or using a separate cache database to the main app. This will overwrite any value set in `config/solid_cache.yml`
@@ -140,17 +169,17 @@ production:
140
169
  ```
141
170
 
142
171
  ```yaml
143
- # config/solid_cache.yml
172
+ # config/cache.yml
144
173
  production:
145
174
  databases: [cache_shard1, cache_shard2, cache_shard3]
146
175
  ```
147
176
 
148
177
  ## Enabling encryption
149
178
 
150
- To encrypt the cache values, you can add set the encrypt property.
179
+ To encrypt the cache values, you can add the encrypt property.
151
180
 
152
181
  ```yaml
153
- # config/solid_cache.yml
182
+ # config/cache.yml
154
183
  production:
155
184
  encrypt: true
156
185
  ```
@@ -178,11 +207,6 @@ config.solid_cache.encryption_context_properties = {
178
207
  }
179
208
  ```
180
209
 
181
- **Note**
182
-
183
- Encryption currently does not work for PostgreSQL, as Rails does not yet support encrypting binary columns for it.
184
- See https://github.com/rails/rails/pull/52650.
185
-
186
210
  ## Index size limits
187
211
  The Solid Cache migrations try to create an index with 1024 byte entries. If that is too big for your database, you should:
188
212
 
data/Rakefile CHANGED
@@ -44,7 +44,7 @@ configs.each do |config|
44
44
  if config == :default
45
45
  sh("bin/rails test")
46
46
  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")
48
48
  end
49
49
  end
50
50
  end
@@ -40,6 +40,8 @@ module SolidCache
40
40
  candidates.pluck(:id)
41
41
  else
42
42
  min_created_at = max_age.seconds.ago
43
+ # We don't have an index on created_at, but we can select
44
+ # the records by id and they'll be in created_at order.
43
45
  candidates.pluck(:id, :created_at)
44
46
  .filter_map { |id, created_at| id if created_at < min_created_at }
45
47
  end
@@ -3,70 +3,13 @@
3
3
  class SolidCache::InstallGenerator < Rails::Generators::Base
4
4
  source_root File.expand_path("templates", __dir__)
5
5
 
6
- def add_rails_cache
7
- gsub_file app_root.join("config/environments/production.rb"),
8
- /(# )?config\.cache_store = (:.*)/, "config.cache_store = :solid_cache_store"
9
- end
10
-
11
- def create_config_solid_cache_yml
12
- template "config/solid_cache.yml"
13
- end
14
-
15
- def add_cache_db_to_database_yml
16
- if app_is_using_sqlite?
17
- gsub_file database_yml, /production:\s*<<: \*default.*/m, sqlite_database_config_with_cache
18
- else
19
- gsub_file database_yml, /production:\s*<<: \*default.*/m, generic_database_config_with_cache
20
- end
21
- end
22
-
23
- def add_solid_cache_db_schema
6
+ def copy_files
7
+ template "config/cache.yml"
24
8
  template "db/cache_schema.rb"
25
9
  end
26
10
 
27
- private
28
- def app_root
29
- Pathname.new(destination_root)
30
- end
31
-
32
- def database_yml
33
- app_root.join("config/database.yml")
34
- end
35
-
36
- def app_is_using_sqlite?
37
- database_yml.read.match?(/production:.*sqlite3/m)
38
- end
39
-
40
- def sqlite_database_config_with_cache
41
- <<~YAML
42
- production:
43
- primary:
44
- <<: *default
45
- database: storage/production.sqlite3
46
- cache:
47
- <<: *default
48
- database: storage/production_cache.sqlite3
49
- migrations_paths: db/cache_migrate
50
- YAML
51
- end
52
-
53
- def app_name_from_production_database_name
54
- database_yml.read.scan(/database: (\w+)_production/).flatten.first
55
- end
56
-
57
- def generic_database_config_with_cache
58
- app_name = app_name_from_production_database_name
59
-
60
- <<~YAML
61
- production:
62
- primary: &production_primary
63
- <<: *default
64
- database: #{app_name}_production
65
- username: #{app_name}
66
- password: <%= ENV["#{app_name.upcase}_DATABASE_PASSWORD"] %>
67
- cache:
68
- <<: *production_primary
69
- database: #{app_name}_production_cache
70
- YAML
71
- end
11
+ def configure_cache_store_adapter
12
+ gsub_file Pathname.new(destination_root).join("config/environments/production.rb"),
13
+ /(# )?config\.cache_store = (:.*)/, "config.cache_store = :solid_cache_store"
14
+ end
72
15
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- ActiveRecord::Schema[8.0].define(version: 1) do
3
+ ActiveRecord::Schema[7.2].define(version: 1) do
4
4
  create_table "solid_cache_entries", force: :cascade do |t|
5
5
  t.binary "key", limit: 1024, null: false
6
6
  t.binary "value", limit: 536870912, null: false
@@ -35,7 +35,7 @@ module SolidCache
35
35
  @connects_to =
36
36
  case
37
37
  when database
38
- { database: { writing: database.to_sym } }
38
+ { shards: { database.to_sym => { writing: database.to_sym } } }
39
39
  when databases
40
40
  { shards: databases.map(&:to_sym).index_with { |database| { writing: database } } }
41
41
  when connects_to
@@ -10,13 +10,16 @@ module SolidCache
10
10
  config.solid_cache = ActiveSupport::OrderedOptions.new
11
11
 
12
12
  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]
14
14
 
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"
18
17
  end
19
18
 
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
+
20
23
  options[:connects_to] = config.solid_cache.connects_to if config.solid_cache.connects_to
21
24
  options[:size_estimate_samples] = config.solid_cache.size_estimate_samples if config.solid_cache.size_estimate_samples
22
25
  options[:encrypt] = config.solid_cache.encrypt if config.solid_cache.encrypt
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidCache
4
- VERSION = "1.0.4"
4
+ VERSION = "1.0.6"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solid_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Donal McBreen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-09-04 00:00:00.000000000 Z
11
+ date: 2024-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -115,7 +115,7 @@ files:
115
115
  - lib/active_support/cache/solid_cache_store.rb
116
116
  - lib/generators/solid_cache/install/USAGE
117
117
  - lib/generators/solid_cache/install/install_generator.rb
118
- - lib/generators/solid_cache/install/templates/config/solid_cache.yml.tt
118
+ - lib/generators/solid_cache/install/templates/config/cache.yml.tt
119
119
  - lib/generators/solid_cache/install/templates/db/cache_schema.rb
120
120
  - lib/solid_cache.rb
121
121
  - lib/solid_cache/configuration.rb
@@ -1,5 +1,4 @@
1
1
  default: &default
2
- database: <%= ENV.fetch("DATABASE", "cache") %>
3
2
  store_options:
4
3
  # Cap age of oldest cache entry to fulfill retention policies
5
4
  # max_age: <%%= 60.days.to_i %>
@@ -13,4 +12,5 @@ test:
13
12
  <<: *default
14
13
 
15
14
  production:
15
+ database: <%= ENV.fetch("DATABASE", "cache") %>
16
16
  <<: *default