diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb index 2db27226f2276d4916d841f1560eb81f01539dbc..ac40e4f987dd5310b63975da6c135a98f562a86b 100644 --- a/activerecord/lib/active_record/attribute_methods.rb +++ b/activerecord/lib/active_record/attribute_methods.rb @@ -104,17 +104,19 @@ def instance_method_already_implemented?(method_name) # +cache_attributes+ allows you to declare which converted attribute values should # be cached. Usually caching only pays off for attributes with expensive conversion - # methods, like date columns (e.g. created_at, updated_at). + # methods, like time related columns (e.g. created_at, updated_at). def cache_attributes(*attribute_names) attribute_names.each {|attr| cached_attributes << attr.to_s} end - # returns the attributes where + # returns the attributes which are cached. + # By default time related columns with datatype :datetime, :timestamp, :time, :date are cached def cached_attributes @cached_attributes ||= columns.select{|c| attribute_types_cached_by_default.include?(c.type)}.map(&:name).to_set end + # returns true if the provided attribute is being cached def cache_attribute?(attr_name) cached_attributes.include?(attr_name) end