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
172
# File 'lib/identity_cache/query_api.rb', line 166

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.



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

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)


181
182
183
184
# File 'lib/identity_cache/query_api.rb', line 181

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