Module: DatastaxRails::AttributeMethods::Read::ClassMethods

Defined in:
lib/datastax_rails/attribute_methods/read.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#cache_attribute?(attr_name) ⇒ Boolean

Returns true if the provided attribute is being cached.

Returns:

  • (Boolean)


30
31
32
# File 'lib/datastax_rails/attribute_methods/read.rb', line 30

def cache_attribute?(attr_name)
  cached_attributes.include?(attr_name)
end

#cache_attributes(*attribute_names) ⇒ Object

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 time related columns (e.g. created_at, updated_at).



19
20
21
# File 'lib/datastax_rails/attribute_methods/read.rb', line 19

def cache_attributes(*attribute_names)
  cached_attributes.merge attribute_names.map(&:to_s)
end

#cached_attributesObject

Returns the attributes which are cached. By default time related columns with datatype :datetime, :timestamp, :time, :date are cached.



25
26
27
# File 'lib/datastax_rails/attribute_methods/read.rb', line 25

def cached_attributes
  @cached_attributes ||= columns.select { |c| cacheable_column?(c) }.map(&:name).to_set
end