Method: LogicalModel::Cache::InstanceMethods#delete_cached

Defined in:
lib/logical_model/cache.rb

#delete_cachedObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/logical_model/cache.rb', line 52

def delete_cached
  model_name = self.class.to_s.pluralize.underscore
  self.class.logger.debug "LogicalModel Log CACHE: Delete cache for #{model_name}\/#{self.id}-.*"
  # Delete cached models
  self.class.cache_store.delete_matched(/#{model_name}\/#{self.id}-.*/)
  
  if self.class.respond_to?(:belongs_to_keys) && !self.class.belongs_to_keys.blank?
    # If it belongs to another model (or models)
    self.class.belongs_to_keys.each do |association_name, association_class|
      model_name = association_class.to_s.pluralize.underscore
      self.class.logger.debug "LogicalModel Log CACHE: Delete cache for #{model_name}\/#{self.send("#{association_name}_id")}-.*"
      # Delete cached models
      self.class.cache_store.delete_matched(/#{model_name}\/#{self.send("#{association_name}_id")}-.*/)
    end
  end
end