identity_cache 1.3.0 → 1.3.1

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: dedbf4998ab4c83ea5d6198af733c3165b9978bd509d9cb135aefd1c1979415d
4
- data.tar.gz: 03cda95c71ef97b89d2b321cbbf8737f12cb841a7eb89bc072419e3fb06b9b9d
3
+ metadata.gz: 3abed29487ae94532060d1a35e2bc86f8b4187cbc9a3074c8c304ab4f8426b4b
4
+ data.tar.gz: ddcaf494c9bc48055ee4e1ddc83a5caf61e047e4d053eb2b4e87a086a73f97ae
5
5
  SHA512:
6
- metadata.gz: 9e81b1259c650b6043e890ea3cdcba24c8e27442ae1609868c82eb1ec2fc2cfb89aae26693bda3cd5489937e78ab959d2fc8c101528238ebdb02bd20832d1408
7
- data.tar.gz: f5bec7a26ff5d896915c6644d475f92429934f179e5d51e8eff9cfa491c117451d542ef6c745509bfead84b631df08ff8f9c8f5dba4b6076ee5b1baf789e94c6
6
+ metadata.gz: e0c8e9d0996d6f7f3f3e760fbf1ec2f7b8fa819bbeeaa3dc8b1286125265da45c6b174a77d3b13f763e6db104d613a55562f0a0ff13eb6d0c800e455ae30020c
7
+ data.tar.gz: 03a5cffffa5a0971f0d12a4d449c518a471d579410c2f7b8dfe32ad82234fb08115fa44cc99e726ed28352ead0287c5e966f47fb0b607758ddb29b1baa4667a4
data/CHANGELOG.md CHANGED
@@ -1,6 +1,11 @@
1
1
  # Identity Cache Changelog
2
2
 
3
- ## unreleased
3
+ ## Unreleased
4
+
5
+ ## 1.3.1
6
+
7
+ ### Fixes
8
+ - Remove N+1 queries from embedded associations when using `fetch` while `should_use_cache` is false. (#531)
4
9
 
5
10
  ## 1.3.0
6
11
 
data/README.md CHANGED
@@ -254,11 +254,26 @@ Cache keys include a version number by default, specified in `IdentityCache::CAC
254
254
 
255
255
  ## Caveats
256
256
 
257
- A word of warning. If an `after_commit` fails before the cache expiry `after_commit` the cache will not be expired and you will be left with stale data.
258
-
259
- Since everything is being marshalled and unmarshalled from Memcached changing Ruby or Rails versions could mean your objects cannot be unmarshalled from Memcached. There are a number of ways to get around this such as namespacing keys when you upgrade or rescuing marshal load errors and treating it as a cache miss. Just something to be aware of if you are using IdentityCache and upgrade Ruby or Rails.
260
-
261
- IdentityCache is also very much _opt-in_ by deliberate design. This means IdentityCache does not mess with the way normal Rails associations work, and including it in a model won't change any clients of that model until you switch them to use `fetch` instead of `find`. This is because there is no way IdentityCache is ever going to be 100% consistent. Processes die, exceptions happen, and network blips occur, which means there is a chance that some database transaction might commit but the corresponding memcached cache invalidation operation does not make it. This means that you need to think carefully about when you use `fetch` and when you use `find`. For example, at Shopify, we never use any `fetch`ers on the path which moves money around, because IdentityCache could simply be wrong, and we want to charge people the right amount of money. We do however use the fetchers on performance critical paths where absolute correctness isn't the most important thing, and this is what IdentityCache is intended for.
257
+ IdentityCache is never going to be 100% consistent, since cache invalidations can be lost. As such, it was intentionally designed to be _opt-in_, so it is only used where cache inconsistency is tolerated. This means IdentityCache does not mess with the way normal Rails associations work, and including it in a model won't change any clients of that model until you switch them to use `fetch` instead of `find`. This means that you need to think carefully about when you use `fetch` and when you use `find`.
258
+
259
+ Expected sources of lost cache invalidations include:
260
+ * Database write performed that doesn't trigger an after_commit callback
261
+ * Process/system getting killed or crashing between the database commit and cache invalidation
262
+ * Network unavailability, including transient failures, preventing the delivery of the cache invalidation
263
+ * Memcached unavailability or failure preventing the processing of the cache invalidation request
264
+ * Memcached flush / restart could remove a cache invalidation that would normally interrupt a cache fill that started when the cache key was absent. E.g.
265
+ 1. cache key absent (not just invalidated)
266
+ 2. process 1 reads cache key
267
+ 3. process 1 starts reading from the database
268
+ 4. process 2 writes to the database
269
+ 5. process 2 writes a cache invalidation marker to cache key
270
+ 6. memcached flush
271
+ 7. process 1 uses an `ADD` operation, which succeeds in filling the cache with the now stale data
272
+ * Rollout of cache namespace changes (e.g. from upgrading IdentityCache, adding columns, cached associations or from application changes to IdentityCache.cache_namespace) can result in cache fills to the new namespace that aren't invalidated by cache invalidations from a process still using the old namespace
273
+
274
+ Cache expiration is meant to be used to help the system recover, but it only works if the application avoids using the cache data as a transaction to write data. IdentityCache avoids loading cached data from its methods during an open transaction, but can't prevent cache data that was loaded before the transaction was opened from being used in a transaction. IdentityCache won't help with scaling write traffic, it was intended for scaling database queries from read-only requests.
275
+
276
+ IdentityCache also caches the absence of database values (e.g. to avoid performance problems when it is destroyed), so lost cache invalidations can also result in that value continuing to remain absent. As such, avoid sending the id of an uncommitted database record to another process (e.g. queuing it to a background job), since that could result in an attempt to read the record by its id before it has been created. A cache invalidation will still be attempted when the record is created, but that could be lost.
262
277
 
263
278
  ## Notes
264
279
 
@@ -70,6 +70,8 @@ module IdentityCache
70
70
  readonly: IdentityCache.fetch_read_only_records && should_use_cache?)
71
71
  return if records.empty?
72
72
 
73
+ return unless should_use_cache?
74
+
73
75
  records.each(&:readonly!) if readonly
74
76
  each_id_embedded_association do |cached_association|
75
77
  preload_id_embedded_association(records, cached_association)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IdentityCache
4
- VERSION = "1.3.0"
4
+ VERSION = "1.3.1"
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.3.0
4
+ version: 1.3.1
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-01-16 00:00:00.000000000 Z
17
+ date: 2023-03-23 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.3.3
193
+ rubygems_version: 3.4.9
194
194
  signing_key:
195
195
  specification_version: 4
196
196
  summary: IdentityCache lets you specify how you want to cache your model objects,