identity_cache 1.5.1 → 1.5.3

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: 74ac4689e3399b1aa302326508b6098665ced3f516637901e87c0a3e12005680
4
- data.tar.gz: e4e5a009cd8820ba6110a750de6069d3f4735673f22111a09a8e86d4f7a6fd85
3
+ metadata.gz: def26128f16258d40ae0aab05bff51da07f3e6290d7742562a968cb061b4e4fa
4
+ data.tar.gz: 5422730f52bed62f919d697c393fc2ead2de6b59edff35f6f6d02f032322c0a9
5
5
  SHA512:
6
- metadata.gz: 8bbe844d4a663b8de0ae1d5231687c3113a13d6922287516d70db5a0dcc11556f3e0529c9353566c06edb6dbeff77cf3f675607440dbe5f266f44c2c72f49fee
7
- data.tar.gz: 447b2c17d61f17012f7100bbee16e063adfc0d9957a4eae0a2b117f7b81a7f5b6083fdc6ecc53bddb7a4204317acbd1a17cc04c3a95f40916df7a16995060fe0
6
+ metadata.gz: 373cb5c7745fa34fd3b512a34ef8646fe3405082f2c174bdc23538827e024180a0275717a9ca7b3c82dd4dbb8ef1847d107a65ccecc5cb253a8608ab68507a60
7
+ data.tar.gz: d7764abbbeaee3b3d48f04d1c9ff2309a18a7eb7fbc3b4a5a2e868a3444ff8e9e2d81776a6f0e9d2d68814fa938de7dce35ab65c8538d7ac313f05bc86f28381
data/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 1.5.3
6
+
7
+ - No longer call `should_use_cache?` on embedded/prefetched associations when reading values
8
+
9
+ ## 1.5.2
10
+
11
+ - Add missing `should_use_cache?` to `fetch_multi` methods.
12
+
5
13
  ## 1.5.1
6
14
 
7
15
  - Fix parent cache invalidation for custom foreign key associations
@@ -65,9 +65,13 @@ module IdentityCache
65
65
  end
66
66
 
67
67
  def fetch_multi(keys, &block)
68
- results = cas_multi(keys, &block)
69
- results = add_multi(keys, &block) if results.nil?
70
- results
68
+ if IdentityCache.should_use_cache?
69
+ results = cas_multi(keys, &block)
70
+ results = add_multi(keys, &block) if results.nil?
71
+ results
72
+ else
73
+ {}
74
+ end
71
75
  end
72
76
 
73
77
  def fetch(key, fill_lock_duration: nil, lock_wait_tries: 2, &block)
@@ -9,7 +9,7 @@ module IdentityCache
9
9
  reflection.active_record.class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
10
10
  def #{cached_accessor_name}
11
11
  association_klass = association(:#{name}).klass
12
- if association_klass.should_use_cache? && #{reflection.foreign_key}.present? && !association(:#{name}).loaded?
12
+ if (loaded_by_idc? || association_klass.should_use_cache?) && #{reflection.foreign_key}.present? && !association(:#{name}).loaded?
13
13
  if defined?(#{records_variable_name})
14
14
  #{records_variable_name}
15
15
  else
@@ -54,7 +54,10 @@ module IdentityCache
54
54
 
55
55
  def load_one_from_db(id)
56
56
  record = build_query(id).take
57
- model.send(:setup_embedded_associations_on_miss, [record]) if record
57
+ if record
58
+ model.send(:setup_embedded_associations_on_miss, [record])
59
+ record.send(:mark_as_loaded_by_idc)
60
+ end
58
61
  record
59
62
  end
60
63
 
@@ -63,6 +66,7 @@ module IdentityCache
63
66
 
64
67
  records = build_query(ids).to_a
65
68
  model.send(:setup_embedded_associations_on_miss, records)
69
+ records.each { |record| record.send(:mark_as_loaded_by_idc) }
66
70
  records.index_by(&:id)
67
71
  end
68
72
 
@@ -25,7 +25,7 @@ module IdentityCache
25
25
  def read(record)
26
26
  assoc = record.association(name)
27
27
 
28
- if assoc.klass.should_use_cache? && !assoc.loaded? && assoc.target.blank?
28
+ if (record.send(:loaded_by_idc?) || assoc.klass.should_use_cache?) && !assoc.loaded? && assoc.target.blank?
29
29
  if record.instance_variable_defined?(records_variable_name)
30
30
  record.instance_variable_get(records_variable_name)
31
31
  elsif record.instance_variable_defined?(dehydrated_variable_name)
@@ -22,7 +22,7 @@ module IdentityCache
22
22
 
23
23
  def #{cached_accessor_name}
24
24
  assoc = association(:#{name})
25
- if assoc.klass.should_use_cache? && !assoc.loaded? && assoc.target.blank?
25
+ if (loaded_by_idc? || assoc.klass.should_use_cache?) && !assoc.loaded? && assoc.target.blank?
26
26
  #{records_variable_name} ||= #{reflection.class_name}.fetch_multi(#{cached_ids_name})
27
27
  else
28
28
  #{name}.to_a
@@ -69,6 +69,7 @@ module IdentityCache
69
69
 
70
70
  def record_from_coder(coder, klass) # :nodoc:
71
71
  record = klass.instantiate(coder[:attributes].dup)
72
+ record.send(:mark_as_loaded_by_idc)
72
73
 
73
74
  if coder.key?(:associations)
74
75
  coder[:associations].each do |name, value|
@@ -21,7 +21,11 @@ module IdentityCache
21
21
  end
22
22
 
23
23
  def fetch_multi(keys)
24
- results = @cache_backend.read_multi(*keys)
24
+ results = if IdentityCache.should_use_cache?
25
+ @cache_backend.read_multi(*keys)
26
+ else
27
+ {}
28
+ end
25
29
  missed_keys = keys - results.keys
26
30
  unless missed_keys.empty?
27
31
  replacement_results = yield missed_keys
@@ -9,5 +9,15 @@ module IdentityCache
9
9
  IdentityCache.should_use_cache?
10
10
  end
11
11
  end
12
+
13
+ private
14
+
15
+ def mark_as_loaded_by_idc
16
+ @loaded_by_idc = true
17
+ end
18
+
19
+ def loaded_by_idc?
20
+ defined?(@loaded_by_idc)
21
+ end
12
22
  end
13
23
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IdentityCache
4
- VERSION = "1.5.1"
4
+ VERSION = "1.5.3"
5
5
  CACHE_VERSION = 8
6
6
  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.5.1
4
+ version: 1.5.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: 2023-12-04 00:00:00.000000000 Z
17
+ date: 2024-01-22 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: activerecord
@@ -190,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
190
190
  - !ruby/object:Gem::Version
191
191
  version: '0'
192
192
  requirements: []
193
- rubygems_version: 3.4.21
193
+ rubygems_version: 3.5.4
194
194
  signing_key:
195
195
  specification_version: 4
196
196
  summary: IdentityCache lets you specify how you want to cache your model objects,