Module: ActiveRecordTweaks::Integration::ClassMethods

Defined in:
lib/active_record_tweaks/integration.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(_base) ⇒ Object



64
65
66
67
68
69
70
71
72
# File 'lib/active_record_tweaks/integration.rb', line 64

def self.extended(_base)
  # rubocop:disable all
  warn ([
    "[DEPRECATION]",
    "`ActiveRecordTweaks::Integration::ClassMethods` is deprecated without replacement.",
    "Please read README in project for details."
  ].join(" "))
  # rubocop:enable all
end

Instance Method Details

#cache_key(*args) ⇒ Object

Returns a cache key for the ActiveRecord class based based on count and maximum value of update timestamp columns (e.g. Cookie based caching with expiration)

Examples:

when record class is empty and has updated timestamp columns or not

Product.cache_key # => "products/all/0"

when record class is not empty but has no updated timestamp columns

Product.cache_key # => "products/all/1"

when record class is not empty and has updated timestamp columns

Person.cache_key # => "people/all/1-20071224150000"

Parameters:

  • args (Array<String, Symbol>)

    The column name with timestamp to check



86
87
88
89
90
91
92
93
94
95
# File 'lib/active_record_tweaks/integration.rb', line 86

def cache_key(*args)
  timestamp_columns = args.empty? ? [:updated_at] : args

  if (timestamp = max_updated_column_timestamp_for_cache_key(timestamp_columns))
    timestamp = timestamp.utc.to_s(cache_timestamp_format)
    "#{model_name.cache_key}/all/#{count}-#{timestamp}"
  else
    cache_key_without_timestamp
  end
end

#cache_key_without_timestampObject

Returns a cache key for the ActiveRecord class based based on count only

Product.cache_key # => "products/all/0" (empty, has updated timestamp columns or not)
Product.cache_key # => "products/all/1" (not empty but has no updated timestamp columns)
Person.cache_key  # => "people/all/1" (not empty and has updated timestamp columns)

Parameters:

  • args (Array<String, Symbol>)

    The column name with timestamp to check



105
106
107
# File 'lib/active_record_tweaks/integration.rb', line 105

def cache_key_without_timestamp
  "#{model_name.cache_key}/all/#{count}"
end