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 +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +5 -1
- data/Gemfile.lock +1 -1
- data/Rakefile +74 -6
- data/dev.yml +4 -0
- data/lib/identity_cache/parent_model_expiration.rb +4 -0
- data/lib/identity_cache/version.rb +1 -1
- data/lib/identity_cache.rb +52 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0daa9d36baa2b4c2e08dc8c29ab55274a1dbfab1d0146010720a68bfe9eff20e
|
4
|
+
data.tar.gz: '08708fb388587b7def00967250321904ffbfa9c071aca71f6b360ea22ec0ab8f'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61e4c7010330259878bb07f61a806b2b8d21d3cfbc67d07074cd9dddafd69471c6aa50ebdf880e39b9a0dba7203d0215f1336829842457ea877e3f065ce8e98e
|
7
|
+
data.tar.gz: e1d0f10f2a4a3ff678b4b89b60547c342ab6a0ce8f5d1623ebcdb29c227e08ee7da8234c32ed3388b745aa11f4be1989d5a554a521152bdd72ebaa9c92cc9747
|
data/.gitignore
CHANGED
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
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
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
data/lib/identity_cache.rb
CHANGED
@@ -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.
|
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-
|
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.
|
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,
|