Module: IdentityCache::QueryAPI
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/identity_cache/query_api.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#expire_attribute_indexes ⇒ Object
:nodoc:.
-
#expire_cache ⇒ Object
:nodoc:.
-
#expire_primary_index ⇒ Object
:nodoc:.
-
#expire_secondary_indexes ⇒ Object
:nodoc:.
-
#fetch_denormalized_cached_association(ivar_name, association_name) ⇒ Object
:nodoc:.
-
#populate_association_caches ⇒ Object
:nodoc:.
-
#populate_denormalized_cached_association(ivar_name, association_name) ⇒ Object
:nodoc:.
-
#was_new_record? ⇒ Boolean
:nodoc:.
Instance Method Details
#expire_attribute_indexes ⇒ Object
:nodoc:
295 296 297 298 299 |
# File 'lib/identity_cache/query_api.rb', line 295 def expire_attribute_indexes # :nodoc: cache_attributes.try(:each) do |(attribute, fields)| IdentityCache.cache.delete(attribute_cache_key_for_attribute_and_previous_values(attribute, fields)) unless was_new_record? end end |
#expire_cache ⇒ Object
:nodoc:
301 302 303 304 305 306 |
# File 'lib/identity_cache/query_api.rb', line 301 def expire_cache # :nodoc: expire_primary_index expire_secondary_indexes expire_attribute_indexes true end |
#expire_primary_index ⇒ Object
:nodoc:
265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/identity_cache/query_api.rb', line 265 def expire_primary_index # :nodoc: return unless self.class.primary_cache_index_enabled extra_keys = if respond_to? :updated_at old_updated_at = old_values_for_fields([:updated_at]).first "expiring_last_updated_at=#{old_updated_at}" else "" end IdentityCache.logger.debug { "[IdentityCache] expiring=#{self.class.name} expiring_id=#{id} #{extra_keys}" } IdentityCache.cache.delete(primary_cache_index_key) end |
#expire_secondary_indexes ⇒ Object
:nodoc:
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
# File 'lib/identity_cache/query_api.rb', line 278 def expire_secondary_indexes # :nodoc: return unless self.class.primary_cache_index_enabled cache_indexes.try(:each) do |fields| if self.destroyed? IdentityCache.cache.delete(secondary_cache_index_key_for_previous_values(fields)) else new_cache_index_key = secondary_cache_index_key_for_current_values(fields) IdentityCache.cache.delete(new_cache_index_key) if !was_new_record? old_cache_index_key = secondary_cache_index_key_for_previous_values(fields) IdentityCache.cache.delete(old_cache_index_key) unless old_cache_index_key == new_cache_index_key end end end end |
#fetch_denormalized_cached_association(ivar_name, association_name) ⇒ Object
:nodoc:
244 245 246 247 248 249 250 251 252 |
# File 'lib/identity_cache/query_api.rb', line 244 def fetch_denormalized_cached_association(ivar_name, association_name) # :nodoc: ivar_full_name = :"@#{ivar_name}" if IdentityCache.should_cache? populate_denormalized_cached_association(ivar_name, association_name) IdentityCache.unmap_cached_nil_for(instance_variable_get(ivar_full_name)) else send(association_name.to_sym) end end |
#populate_association_caches ⇒ Object
:nodoc:
233 234 235 236 237 238 239 240 241 242 |
# File 'lib/identity_cache/query_api.rb', line 233 def populate_association_caches # :nodoc: self.class.all_cached_associations_needing_population.each do |cached_association, | send([:population_method_name]) reflection = [:embed] && self.class.reflect_on_association(cached_association) if reflection && reflection.klass.respond_to?(:cached_has_manys) child_objects = Array.wrap(send([:cached_accessor_name])) child_objects.each(&:populate_association_caches) end end end |
#populate_denormalized_cached_association(ivar_name, association_name) ⇒ Object
:nodoc:
254 255 256 257 258 259 260 261 262 263 |
# File 'lib/identity_cache/query_api.rb', line 254 def populate_denormalized_cached_association(ivar_name, association_name) # :nodoc: ivar_full_name = :"@#{ivar_name}" value = instance_variable_get(ivar_full_name) return value unless value.nil? loaded_association = send(association_name) instance_variable_set(ivar_full_name, IdentityCache.map_cached_nil_for(loaded_association)) end |
#was_new_record? ⇒ Boolean
:nodoc:
308 309 310 |
# File 'lib/identity_cache/query_api.rb', line 308 def was_new_record? # :nodoc: !destroyed? && transaction_changed_attributes.has_key?('id') && transaction_changed_attributes['id'].nil? end |