method
cache_key
v7.1.3.4 -
Show latest stable
-
0 notes -
Class: ActiveRecord::Relation
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0
- 3.0.9
- 3.1.0
- 3.2.1
- 3.2.8
- 3.2.13
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1 (0)
- 5.1.7 (0)
- 5.2.3 (0)
- 6.0.0 (-38)
- 6.1.3.1 (0)
- 6.1.7.7 (0)
- 7.0.0 (0)
- 7.1.3.2 (0)
- 7.1.3.4 (0)
- What's this?
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)