Module: IdentityCache::QueryAPI
- Extended by:
- ActiveSupport::Concern
- Included in:
- WithoutPrimaryIndex
- Defined in:
- lib/identity_cache/query_api.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#_run_commit_callbacks ⇒ Object
Override the method that is used to call after_commit callbacks so that we can expire the caches before other after_commit callbacks.
-
#expire_cache ⇒ Object
Invalidate the cache data associated with the record.
- #was_new_record? ⇒ Boolean private
Instance Method Details
#_run_commit_callbacks ⇒ Object
Override the method that is used to call after_commit callbacks so that we can expire the caches before other after_commit callbacks. This way we can avoid stale cache reads that happen from the ordering of callbacks. For example, if an after_commit callback enqueues a background job, then we don’t want it to be possible for the background job to run and load data from the cache before it is invalidated.
168 169 170 171 172 173 |
# File 'lib/identity_cache/query_api.rb', line 168 def _run_commit_callbacks if destroyed? || transaction_changed_attributes.present? expire_cache end super end |
#expire_cache ⇒ Object
Invalidate the cache data associated with the record. Returns ‘true` on success, `false` otherwise.
177 178 179 180 181 182 |
# File 'lib/identity_cache/query_api.rb', line 177 def expire_cache expired_parent_caches = expire_parent_caches expired_attribute_indexes = expire_attribute_indexes expired_parent_caches && expired_attribute_indexes end |
#was_new_record? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
185 186 187 188 |
# File 'lib/identity_cache/query_api.rb', line 185 def was_new_record? # :nodoc: pk = self.class.primary_key !destroyed? && transaction_changed_attributes.key?(pk) && transaction_changed_attributes[pk].nil? end |