As a starting point, you can try something like this:
def self.cache_key ["#{model_name.cache_key}-all", "#{count}-#{updated_at.utc.to_s(cache_timestamp_format) rescue 'empty'}" ] * '/' end def self.updated_at maximum :updated_at end
I have a normalized database where several models refer to the same other model, think about clients, locations, etc., all have addresses using street_id.
With this solution, you can create cache keys based on scope, e.g.
cache [@client, @client.locations] do
and I could just change self.updated top to also include related objects (because has_many does not support โtouchโ, so if I update the street, it will not be visible in the cache otherwise):
belongs_to :street def cache_key [street.cache_key, super] * '/' end
Until you โrestoreโ records and use touch in the property, you should be fine with the assumption that the cache key, consisting of count and max updated_at, is sufficient.
source share