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.



163
164
165
166
167
168
169
# File 'lib/identity_cache/query_api.rb', line 163

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

#expire_cacheObject

Invalidate the cache data associated with the record.



172
173
174
175
# File 'lib/identity_cache/query_api.rb', line 172

def expire_cache
  expire_attribute_indexes
  true
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)


178
179
180
181
# File 'lib/identity_cache/query_api.rb', line 178

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