@@ -60,7 +60,7 @@ class AssociationError < StandardError; end
60
60
61
61
class InverseAssociationError < StandardError ; end
62
62
63
- class NestedDeferredParentBlockError < StandardError ; end
63
+ class NestedDeferredCacheExpirationBlockError < StandardError ; end
64
64
65
65
class UnsupportedScopeError < StandardError ; end
66
66
@@ -202,42 +202,51 @@ def fetch_multi(*keys)
202
202
result
203
203
end
204
204
205
- # Executes a block with deferred parent expiration, ensuring that the parent
206
- # records' cache expiration is deferred until the block completes. When the block
207
- # completes, it triggers expiration of the primary index for the parent records.
208
- # Raises a NestedDeferredParentBlockError if a deferred parent expiration block
209
- # is already active on the current thread.
205
+ # Executes a block with deferred cache expiration, ensuring that the records' (parent,
206
+ # children and attributes) cache expiration is deferred until the block completes. When
207
+ # the block completes, it issues delete_multi calls for all the records and attributes
208
+ # that were marked for expiration.
210
209
#
211
210
# == Parameters:
212
211
# No parameters.
213
212
#
214
213
# == Raises:
215
- # NestedDeferredParentBlockError if a deferred parent expiration block is already active.
214
+ # NestedDeferredCacheExpirationBlockError if a deferred cache expiration block is already active.
216
215
#
217
216
# == Yield:
218
- # Runs the provided block with deferred parent expiration.
217
+ # Runs the provided block with deferred cache expiration.
219
218
#
220
219
# == Returns:
221
220
# The result of executing the provided block.
222
221
#
223
222
# == Ensures:
224
- # Cleans up thread-local variables related to deferred parent expiration regardless
223
+ # Cleans up thread-local variables related to deferred cache expiration regardless
225
224
# of whether the block raises an exception.
226
- def with_deferred_parent_expiration
227
- raise NestedDeferredParentBlockError if Thread . current [ :idc_deferred_parent_expiration ]
225
+ def with_deferred_expiration
226
+ raise NestedDeferredCacheExpirationBlockError if Thread . current [ :idc_deferred_expiration ]
228
227
229
- Thread . current [ :idc_deferred_parent_expiration ] = true
230
- Thread . current [ :idc_parent_records_for_cache_expiry ] = Set . new
228
+ Thread . current [ :idc_deferred_expiration ] = true
229
+ Thread . current [ :idc_records_to_expire ] = Set . new
230
+ Thread . current [ :idc_attributes_to_expire ] = Set . new
231
231
232
232
result = yield
233
233
234
- Thread . current [ :idc_deferred_parent_expiration ] = nil
235
- Thread . current [ :idc_parent_records_for_cache_expiry ] . each ( &:expire_primary_index )
236
-
234
+ Thread . current [ :idc_deferred_expiration ] = nil
235
+ if Thread . current [ :idc_records_to_expire ] . any?
236
+ IdentityCache . cache . delete_multi (
237
+ Thread . current [ :idc_records_to_expire ]
238
+ )
239
+ end
240
+ if Thread . current [ :idc_attributes_to_expire ] . any?
241
+ IdentityCache . cache . delete_multi (
242
+ Thread . current [ :idc_attributes_to_expire ]
243
+ )
244
+ end
237
245
result
238
246
ensure
239
- Thread . current [ :idc_deferred_parent_expiration ] = nil
240
- Thread . current [ :idc_parent_records_for_cache_expiry ] . clear
247
+ Thread . current [ :idc_deferred_expiration ] = nil
248
+ Thread . current [ :idc_records_to_expire ] . clear
249
+ Thread . current [ :idc_attributes_to_expire ] . clear
241
250
end
242
251
243
252
def with_fetch_read_only_records ( value = true )
0 commit comments