Module: LastModCache::InstanceMethods

Defined in:
lib/last_mod_cache.rb

Instance Method Summary collapse

Instance Method Details

#method_missing_with_last_mod_cache(method, *args, &block) ⇒ Object

:nodoc:



234
235
236
237
238
239
240
241
242
243
244
# File 'lib/last_mod_cache.rb', line 234

def method_missing_with_last_mod_cache(method, *args, &block) #:nodoc:
  match = method.to_s.match(ASSOCIATION_WITH_CACHE_PATTERN)
  association_name = match[1].to_sym if match
  reflection = self.class.reflect_on_association(association_name) if association_name
  if reflection && (reflection.macro == :belongs_to)
    foreign_key = reflection.respond_to?(:foreign_key) ? reflection.foreign_key : reflection.primary_key_name
    reflection.klass.first_with_cache(:conditions => {(reflection.options[:primary_key] || reflection.klass.primary_key) => self[foreign_key]})
  else
    method_missing_without_last_mod_cache(method, *args, &block)
  end
end

#update_timestamp!Object

Force an update to the timestamp column. This method can be invoked to force cache entries to expire. Validations and callbacks will not be called. If you need those called, simply call update_attribute instead.



225
226
227
228
229
230
231
232
# File 'lib/last_mod_cache.rb', line 225

def update_timestamp!
  col_name = self.class.updated_at_column
  self.send("#{col_name}=", Time.now)
  timestamp = self.send(col_name)
  conn = self.class.connection
  sql = self.class.send(:sanitize_sql, ["UPDATE #{conn.quote_table_name(self.class.table_name)} SET #{conn.quote_column_name(col_name)} = ? WHERE #{conn.quote_column_name(self.class.primary_key)} = ?", timestamp, id])
  conn.update(sql)
end