solid_cache 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a27107ddce2c64a1884881e7cd3385533c32c1c13e2eee486a8c856de233c00
4
- data.tar.gz: a1eb035fd95c8cadfbcce86603ed4ec2dcc0a133c9516101baf0dca94f1baf7d
3
+ metadata.gz: 1cf02364d38d08f18cbe3d9811a7957018ec23ebaf08951c51110204eea237de
4
+ data.tar.gz: c04b221f9c37fdc78f78e07143afe33bc1d346695ef8c910dc986533dd460a38
5
5
  SHA512:
6
- metadata.gz: 8d0633c3f33b02df9f18e0f77b1ca6b200333bd6961d74af4462311a2ede3f264f6bf6f845da48ed187049affa9984f9aa43cfa39529ddaf192715c3940445bc
7
- data.tar.gz: 819e979a65563ec3ce5e16c09b8800a80e5764b63938f1e7e2b64d38ea453a06dec8f6ba63c8589cd4bbff05632b65d47c595de5c949997ef18f47305435cfd5
6
+ metadata.gz: 725fa1c931e54f8aa743aa8311fd05f44fe200904ede83bcb1207377f54926c330abe887a2dfb04c956f703f8e673b38f8af219a31e04c2f1d653cdbe0b980db
7
+ data.tar.gz: 6d793397978b7d1e1797ed4b97726dc25c1e053a8a8dc2aa9b39669bbb79c3a9d7b9d0d676e43bea4f1a401ae7528a1aee34c5985899e96e092b86c1be4c2f0a
data/README.md CHANGED
@@ -9,9 +9,9 @@ Solid Cache is configured by default in new Rails 8 applications. But if you're
9
9
  1. `bundle add solid_cache`
10
10
  2. `bin/rails solid_cache:install`
11
11
 
12
- This will configure Solid Cache as the production cache store, create `config/solid_cache.yml`, create `db/cache_schema.rb`, and attempt to 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
13
 
14
- If you've already made material changes to your `config/database.yml` file, the installer may not be able to add the cache db configuration directly. If you need to do it yourself, this is what it should look like:
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
15
 
16
16
  ```yaml
17
17
  production:
@@ -43,7 +43,7 @@ Then run `db:prepare` in production to ensure the database is created and the sc
43
43
 
44
44
  ## Configuration
45
45
 
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.
47
47
 
48
48
  The format of the file is:
49
49
 
@@ -91,7 +91,7 @@ If none of these are set, Solid Cache will use the `ActiveRecord::Base` connecti
91
91
 
92
92
  ### Engine configuration
93
93
 
94
- There are three options that can be set on the engine:
94
+ There are five options that can be set on the engine:
95
95
 
96
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
97
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`
@@ -169,17 +169,17 @@ production:
169
169
  ```
170
170
 
171
171
  ```yaml
172
- # config/solid_cache.yml
172
+ # config/cache.yml
173
173
  production:
174
174
  databases: [cache_shard1, cache_shard2, cache_shard3]
175
175
  ```
176
176
 
177
177
  ## Enabling encryption
178
178
 
179
- To encrypt the cache values, you can add set the encrypt property.
179
+ To encrypt the cache values, you can add the encrypt property.
180
180
 
181
181
  ```yaml
182
- # config/solid_cache.yml
182
+ # config/cache.yml
183
183
  production:
184
184
  encrypt: true
185
185
  ```
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[7.1].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.5"
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.5
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-05 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
@@ -158,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
158
  - !ruby/object:Gem::Version
159
159
  version: '0'
160
160
  requirements: []
161
- rubygems_version: 3.5.17
161
+ rubygems_version: 3.5.11
162
162
  signing_key:
163
163
  specification_version: 4
164
164
  summary: A database backed ActiveSupport::Cache::Store
@@ -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