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

Instance Method Details

#_run_commit_callbacksObject

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.



166
167
168
169
170
171
# File 'lib/identity_cache/query_api.rb', line 166

def _run_commit_callbacks
  if destroyed? || transaction_changed_attributes.present?
    expire_cache
  end
  super
end

#expire_cacheObject

Invalidate the cache data associated with the record. Returns true on success, false otherwise.



175
176
177
178
179
180
# File 'lib/identity_cache/query_api.rb', line 175

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.

Returns:

  • (Boolean)


183
184
185
186
# File 'lib/identity_cache/query_api.rb', line 183

def was_new_record? # :nodoc:
  pk = self.class.primary_key
  !destroyed? && transaction_changed_attributes.key?(pk) && transaction_changed_attributes[pk].nil?
end