v6.1.3.1 - Show latest stable - 0 notes - Class: ActiveRecord::Relation
cache_key(timestamp_column = "updated_at") public

Returns a stable cache key that can be used to identify this query. The cache key is built with a fingerprint of the SQL query.

Product.where("name like ?", "%Cosmic Encounter%").cache_key
# => "products/query-1850ab3d302391b85b8693e941286659"

If ActiveRecord::Base.collection_cache_versioning is turned off, as it was in Rails 6.0 and earlier, the cache key will also include a version.

ActiveRecord::Base.collection_cache_versioning = false
Product.where("name like ?", "%Cosmic Encounter%").cache_key
# => "products/query-1850ab3d302391b85b8693e941286659-1-20150714212553907087000"

You can also pass a custom timestamp column to fetch the timestamp of the last updated record.

Product.where("name like ?", "%Game%").cache_key(:last_reviewed_at)
Show source
Register or log in to add new notes.