identity_cache 1.2.0 → 1.3.0

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: 561965856845fc5d5094581d735584924eda58557edfb3831c39bce2498635aa
4
- data.tar.gz: 33a85428a3b2a298076d81a79b662b742c00a25971bf453f8f57eeab7cba2681
3
+ metadata.gz: dedbf4998ab4c83ea5d6198af733c3165b9978bd509d9cb135aefd1c1979415d
4
+ data.tar.gz: 03cda95c71ef97b89d2b321cbbf8737f12cb841a7eb89bc072419e3fb06b9b9d
5
5
  SHA512:
6
- metadata.gz: 6a8c691d8883acfd69f11724dfff13a3ef4858a2abd2ca658659981f1d08b36dea244100c4030b8ef5d39ac8509e639fea6cd02127e09d157be636fcc2bee77a
7
- data.tar.gz: e357c3a4f02a288a5ddb3290cbd11176937821bb3c9052fb318d9139ac253650f7018a8249b2ebc9f115015a6434baf7cb1b7e76bfb0dbf1e98ee745e3e95ed7
6
+ metadata.gz: 9e81b1259c650b6043e890ea3cdcba24c8e27442ae1609868c82eb1ec2fc2cfb89aae26693bda3cd5489937e78ab959d2fc8c101528238ebdb02bd20832d1408
7
+ data.tar.gz: f5bec7a26ff5d896915c6644d475f92429934f179e5d51e8eff9cfa491c117451d542ef6c745509bfead84b631df08ff8f9c8f5dba4b6076ee5b1baf789e94c6
@@ -16,14 +16,14 @@ jobs:
16
16
  matrix:
17
17
  entry:
18
18
  - name: 'Minimum supported'
19
- ruby: '2.5'
19
+ ruby: '2.7'
20
20
  gemfile: "Gemfile.min-supported"
21
21
  - name: 'Latest released & run rubocop'
22
- ruby: '3.0'
22
+ ruby: '3.2'
23
23
  gemfile: "Gemfile.latest-release"
24
24
  rubocop: true
25
25
  - name: 'Rails edge'
26
- ruby: '3.0'
26
+ ruby: '3.2'
27
27
  gemfile: "Gemfile.rails-edge"
28
28
  edge: true
29
29
 
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Identity Cache Changelog
2
2
 
3
+ ## unreleased
4
+
5
+ ## 1.3.0
6
+
7
+ ### Features
8
+ - Return meaningful value from `expire_cache` indicating whenever it succeeded or failed in the process. (#523)
9
+
10
+ ### Fixes
11
+ - Expire parents cache when when calling `expire_cache`. (#523)
12
+ - Avoid creating too many shapes on Ruby 3.2+. (#526)
13
+
3
14
  ## 1.2.0
4
15
 
5
16
  ### Fixes
data/dev.yml CHANGED
@@ -5,7 +5,7 @@ up:
5
5
  - mysql-client@5.7:
6
6
  or: [mysql@5.7]
7
7
  conflicts: [mysql-connector-c, mysql, mysql-client]
8
- - ruby: 2.7.2
8
+ - ruby: 3.2.0
9
9
  - isogun
10
10
  - bundler
11
11
 
@@ -44,7 +44,7 @@ module IdentityCache
44
44
  # @param db_key [Array] Reference to what to load from the database.
45
45
  # @return [Hash] A hash mapping each database key to its corresponding value
46
46
  def load_multi(cache_fetcher, db_keys)
47
- load_batch(cache_fetcher => db_keys).fetch(cache_fetcher)
47
+ load_batch({ cache_fetcher => db_keys }).fetch(cache_fetcher)
48
48
  end
49
49
 
50
50
  # Load multiple keys for multiple cache fetchers
@@ -35,16 +35,20 @@ module IdentityCache
35
35
  end
36
36
 
37
37
  def expire(record)
38
+ all_deleted = true
39
+
38
40
  unless record.send(:was_new_record?)
39
41
  old_key = old_cache_key(record)
40
- IdentityCache.cache.delete(old_key)
42
+ all_deleted = IdentityCache.cache.delete(old_key)
41
43
  end
42
44
  unless record.destroyed?
43
45
  new_key = new_cache_key(record)
44
46
  if new_key != old_key
45
- IdentityCache.cache.delete(new_key)
47
+ all_deleted = IdentityCache.cache.delete(new_key) && all_deleted
46
48
  end
47
49
  end
50
+
51
+ all_deleted
48
52
  end
49
53
 
50
54
  def cache_key(index_key)
@@ -45,8 +45,9 @@ module IdentityCache
45
45
  def expire_parent_caches
46
46
  parents_to_expire = Set.new
47
47
  add_parents_to_cache_expiry_set(parents_to_expire)
48
- parents_to_expire.each do |parent|
49
- parent.expire_primary_index if parent.class.primary_cache_index_enabled
48
+ parents_to_expire.select! { |parent| parent.class.primary_cache_index_enabled }
49
+ parents_to_expire.reduce(true) do |all_expired, parent|
50
+ parent.expire_primary_index && all_expired
50
51
  end
51
52
  end
52
53
 
@@ -166,15 +166,17 @@ module IdentityCache
166
166
  def _run_commit_callbacks
167
167
  if destroyed? || transaction_changed_attributes.present?
168
168
  expire_cache
169
- expire_parent_caches
170
169
  end
171
170
  super
172
171
  end
173
172
 
174
- # Invalidate the cache data associated with the record.
173
+ # Invalidate the cache data associated with the record. Returns `true` on success,
174
+ # `false` otherwise.
175
175
  def expire_cache
176
- expire_attribute_indexes
177
- true
176
+ expired_parent_caches = expire_parent_caches
177
+ expired_attribute_indexes = expire_attribute_indexes
178
+
179
+ expired_parent_caches && expired_attribute_indexes
178
180
  end
179
181
 
180
182
  # @api private
@@ -185,9 +187,11 @@ module IdentityCache
185
187
 
186
188
  private
187
189
 
190
+ # Even if we have problems with some attributes, carry over the results and expire
191
+ # all possible attributes without array allocation.
188
192
  def expire_attribute_indexes # :nodoc:
189
- cache_indexes.each do |cached_attribute|
190
- cached_attribute.expire(self)
193
+ cache_indexes.reduce(true) do |all_expired, cached_attribute|
194
+ cached_attribute.expire(self) && all_expired
191
195
  end
192
196
  end
193
197
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IdentityCache
4
- VERSION = "1.2.0"
4
+ VERSION = "1.3.0"
5
5
  CACHE_VERSION = 8
6
6
  end
@@ -7,8 +7,9 @@ module IdentityCache
7
7
  include WithoutPrimaryIndex
8
8
 
9
9
  def expire_cache
10
- expire_primary_index
11
- super
10
+ expired_primary_index = expire_primary_index
11
+
12
+ super && expired_primary_index
12
13
  end
13
14
 
14
15
  # @api private
@@ -158,6 +159,15 @@ module IdentityCache
158
159
  def expire_primary_key_cache_index(id)
159
160
  cached_primary_index.expire(id)
160
161
  end
162
+
163
+ private
164
+
165
+ def inherited(subclass)
166
+ super
167
+ subclass.class_eval do
168
+ @cached_primary_index = nil
169
+ end
170
+ end
161
171
  end
162
172
  end
163
173
  end
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.2.0
4
+ version: 1.3.0
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: 2022-08-15 00:00:00.000000000 Z
17
+ date: 2023-01-16 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: activerecord