identity_cache 1.6.2 → 1.6.3

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: 463112ddb217364a26a8232ef1958c45bdb24fc7dcd891be3e7d4db4ca4d29a4
4
- data.tar.gz: 13ea742aca4c33f710a6f8a229f6cf0531dba50291c1ec7c67bce735028ce527
3
+ metadata.gz: 0daa9d36baa2b4c2e08dc8c29ab55274a1dbfab1d0146010720a68bfe9eff20e
4
+ data.tar.gz: '08708fb388587b7def00967250321904ffbfa9c071aca71f6b360ea22ec0ab8f'
5
5
  SHA512:
6
- metadata.gz: d4c3cae9c3c4a6444f62d84242326da8901e0aa66895c8b6d2916930a5824fe402299d5e7c6270982e37fa9cd97991310756320aea0fb93b64a1f515a27f1c1f
7
- data.tar.gz: 5512f9b845a4bc9ea8821d6e8563bc4307ba46a32fe32f1f5d2a708b624be3a5ed72c1b64fe2a9ade21f52ffa8d6c3220e23bc3bb433249bceb4d6eacdf7ba67
6
+ metadata.gz: 61e4c7010330259878bb07f61a806b2b8d21d3cfbc67d07074cd9dddafd69471c6aa50ebdf880e39b9a0dba7203d0215f1336829842457ea877e3f065ce8e98e
7
+ data.tar.gz: e1d0f10f2a4a3ff678b4b89b60547c342ab6a0ce8f5d1623ebcdb29c227e08ee7da8234c32ed3388b745aa11f4be1989d5a554a521152bdd72ebaa9c92cc9747
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ test/version_tmp
16
16
  tmp
17
17
  .rubocop-http*
18
18
  .byebug_history
19
+ gemfiles/*.lock
data/CHANGELOG.md CHANGED
@@ -2,9 +2,13 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 1.6.3
6
+
7
+ - Split the `with_deferred_parent_expiration` and `with_deferred_parent_expiration`. (#578)
8
+
5
9
  ## 1.6.2
6
10
 
7
- - Support deferred expiry of associations and attributes. Add a rake task to create test database.
11
+ - Support deferred expiry of associations and attributes. Add a rake task to create test database. (#577)
8
12
 
9
13
  ## 1.6.1
10
14
 
data/Gemfile.lock CHANGED
@@ -8,7 +8,7 @@ GIT
8
8
  PATH
9
9
  remote: .
10
10
  specs:
11
- identity_cache (1.6.2)
11
+ identity_cache (1.6.3)
12
12
  activerecord (>= 7.0)
13
13
  ar_transaction_changes (~> 1.1)
14
14
 
data/Rakefile CHANGED
@@ -9,14 +9,82 @@ require "rdoc/task"
9
9
  desc("Default: run tests and style checks.")
10
10
  task(default: [:test, :rubocop])
11
11
 
12
- desc("Test the identity_cache plugin.")
13
- Rake::TestTask.new(:test) do |t|
14
- t.libs << "lib"
15
- t.libs << "test"
16
- t.pattern = "test/**/*_test.rb"
17
- t.verbose = true
12
+ namespace :test do
13
+ desc "Test the identity_cache plugin with default Gemfile"
14
+ Rake::TestTask.new(:default) do |t|
15
+ t.libs << "lib"
16
+ t.libs << "test"
17
+ t.pattern = "test/**/*_test.rb"
18
+ t.verbose = true
19
+ end
20
+
21
+ desc "Test the identity_cache plugin with minimum supported dependencies"
22
+ task :min_supported do
23
+ gemfile = File.expand_path("gemfiles/Gemfile.min-supported", __dir__)
24
+ ENV["BUNDLE_GEMFILE"] = gemfile
25
+
26
+ puts "\nInstalling dependencies for #{gemfile}..."
27
+ Bundler.with_unbundled_env do
28
+ system("bundle install --gemfile #{gemfile}") || abort("Bundle install failed")
29
+ end
30
+
31
+ puts "Running tests with #{gemfile}..."
32
+ Rake::TestTask.new(:run_min_supported) do |t|
33
+ t.libs << "lib"
34
+ t.libs << "test"
35
+ t.pattern = "test/**/*_test.rb"
36
+ t.verbose = true
37
+ end
38
+ Rake::Task["run_min_supported"].invoke
39
+ end
40
+
41
+ desc "Test the identity_cache plugin with latest released dependencies"
42
+ task :latest_release do
43
+ gemfile = File.expand_path("gemfiles/Gemfile.latest-release", __dir__)
44
+ ENV["BUNDLE_GEMFILE"] = gemfile
45
+
46
+ puts "\nInstalling dependencies for #{gemfile}..."
47
+ Bundler.with_unbundled_env do
48
+ system("bundle install --gemfile #{gemfile}") || abort("Bundle install failed")
49
+ end
50
+
51
+ puts "Running tests with #{gemfile}..."
52
+ Rake::TestTask.new(:run_latest_release) do |t|
53
+ t.libs << "lib"
54
+ t.libs << "test"
55
+ t.pattern = "test/**/*_test.rb"
56
+ t.verbose = true
57
+ end
58
+ Rake::Task["run_latest_release"].invoke
59
+ end
60
+
61
+ desc "Test the identity_cache plugin with rails edge dependencies"
62
+ task :rails_edge do
63
+ gemfile = File.expand_path("gemfiles/Gemfile.rails-edge", __dir__)
64
+ ENV["BUNDLE_GEMFILE"] = gemfile
65
+
66
+ puts "\nInstalling dependencies for #{gemfile}..."
67
+ Bundler.with_unbundled_env do
68
+ system("bundle install --gemfile #{gemfile}") || abort("Bundle install failed")
69
+ end
70
+
71
+ puts "Running tests with #{gemfile}..."
72
+ Rake::TestTask.new(:run_rails_edge) do |t|
73
+ t.libs << "lib"
74
+ t.libs << "test"
75
+ t.pattern = "test/**/*_test.rb"
76
+ t.verbose = true
77
+ end
78
+ Rake::Task["run_rails_edge"].invoke
79
+ end
18
80
  end
19
81
 
82
+ desc "Run default tests"
83
+ task test: ["test:default"]
84
+
85
+ desc "Run all tests (default, min_supported, latest_release, rails_edge)"
86
+ task test_all: ["test:default", "test:min_supported", "test:latest_release", "test:rails_edge"]
87
+
20
88
  task :rubocop do
21
89
  require "rubocop/rake_task"
22
90
  RuboCop::RakeTask.new
data/dev.yml CHANGED
@@ -24,6 +24,10 @@ commands:
24
24
  bundle exec ruby -I test "$@"
25
25
  fi
26
26
 
27
+ test-all:
28
+ desc: "Run tests for all gemfiles (default, min_supported, latest_release, rails_edge)"
29
+ run: bundle exec rake test_all
30
+
27
31
  style:
28
32
  desc: "Run rubocop checks"
29
33
  run: bundle exec rubocop "$@"
@@ -47,6 +47,10 @@ module IdentityCache
47
47
  add_parents_to_cache_expiry_set(parents_to_expire)
48
48
  parents_to_expire.select! { |parent| parent.class.primary_cache_index_enabled }
49
49
  parents_to_expire.reduce(true) do |all_expired, parent|
50
+ if Thread.current[:idc_deferred_parent_expiration]
51
+ Thread.current[:idc_parent_records_for_cache_expiry] << parent
52
+ next parent
53
+ end
50
54
  parent.expire_primary_index && all_expired
51
55
  end
52
56
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IdentityCache
4
- VERSION = "1.6.2"
4
+ VERSION = "1.6.3"
5
5
  CACHE_VERSION = 8
6
6
  end
@@ -60,6 +60,8 @@ module IdentityCache
60
60
 
61
61
  class InverseAssociationError < StandardError; end
62
62
 
63
+ class NestedDeferredParentBlockError < StandardError; end
64
+
63
65
  class NestedDeferredCacheExpirationBlockError < StandardError; end
64
66
 
65
67
  class UnsupportedScopeError < StandardError; end
@@ -202,6 +204,48 @@ module IdentityCache
202
204
  result
203
205
  end
204
206
 
207
+ # Executes a block with deferred parent expiration, ensuring that the parent
208
+ # records' cache expiration is deferred until the block completes. When the block
209
+ # completes, it triggers expiration of the primary index for the parent records.
210
+ # Raises a NestedDeferredParentBlockError if a deferred parent expiration block
211
+ # is already active on the current thread.
212
+ #
213
+ # == Parameters:
214
+ # No parameters.
215
+ #
216
+ # == Raises:
217
+ # NestedDeferredParentBlockError if a deferred parent expiration block is already active.
218
+ #
219
+ # == Yield:
220
+ # Runs the provided block with deferred parent expiration.
221
+ #
222
+ # == Returns:
223
+ # The result of executing the provided block.
224
+ #
225
+ # == Ensures:
226
+ # Cleans up thread-local variables related to deferred parent expiration regardless
227
+ # of whether the block raises an exception.
228
+ def with_deferred_parent_expiration
229
+ raise NestedDeferredParentBlockError if Thread.current[:idc_deferred_parent_expiration]
230
+
231
+ if Thread.current[:idc_deferred_expiration]
232
+ deprecator.deprecation_warning("`with_deferred_parent_expiration`")
233
+ end
234
+
235
+ Thread.current[:idc_deferred_parent_expiration] = true
236
+ Thread.current[:idc_parent_records_for_cache_expiry] = Set.new
237
+
238
+ result = yield
239
+
240
+ Thread.current[:idc_deferred_parent_expiration] = nil
241
+ Thread.current[:idc_parent_records_for_cache_expiry].each(&:expire_primary_index)
242
+
243
+ result
244
+ ensure
245
+ Thread.current[:idc_deferred_parent_expiration] = nil
246
+ Thread.current[:idc_parent_records_for_cache_expiry]&.clear
247
+ end
248
+
205
249
  # Executes a block with deferred cache expiration, ensuring that the records' (parent,
206
250
  # children and attributes) cache expiration is deferred until the block completes. When
207
251
  # the block completes, it issues delete_multi calls for all the records and attributes
@@ -225,6 +269,10 @@ module IdentityCache
225
269
  def with_deferred_expiration
226
270
  raise NestedDeferredCacheExpirationBlockError if Thread.current[:idc_deferred_expiration]
227
271
 
272
+ if Thread.current[:idc_deferred_parent_expiration]
273
+ deprecator.deprecation_warning("`with_deferred_parent_expiration`")
274
+ end
275
+
228
276
  Thread.current[:idc_deferred_expiration] = true
229
277
  Thread.current[:idc_records_to_expire] = Set.new
230
278
  Thread.current[:idc_attributes_to_expire] = Set.new
@@ -268,6 +316,10 @@ module IdentityCache
268
316
  ParentModelExpiration.install_all_pending_parent_expiry_hooks
269
317
  end
270
318
 
319
+ def deprecator
320
+ @deprecator ||= ActiveSupport::Deprecation.new("1.7.0", "IdentityCache")
321
+ end
322
+
271
323
  private
272
324
 
273
325
  def fetch_in_batches(keys, &block)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: identity_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.2
4
+ version: 1.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Camilo Lopez
@@ -14,7 +14,7 @@ authors:
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2024-10-10 00:00:00.000000000 Z
17
+ date: 2024-10-22 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: activerecord
@@ -191,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
191
191
  - !ruby/object:Gem::Version
192
192
  version: '0'
193
193
  requirements: []
194
- rubygems_version: 3.5.21
194
+ rubygems_version: 3.5.22
195
195
  signing_key:
196
196
  specification_version: 4
197
197
  summary: IdentityCache lets you specify how you want to cache your model objects,