method

cache_version

Importance_2
Ruby on Rails latest stable (v7.1.3.2) - 0 notes - Class: ActiveRecord::Relation
cache_version(timestamp_column = :updated_at) public

Returns a cache version that can be used together with the cache key to form a recyclable caching scheme. The cache version is built with the number of records matching the query, and the timestamp of the last updated record. When a new record comes to match the query, or any of the existing records is updated or deleted, the cache version changes.

If the collection is loaded, the method will iterate through the records to generate the timestamp, otherwise it will trigger one SQL query like:

SELECT COUNT(*), MAX("products"."updated_at") FROM "products" WHERE (name like '%Cosmic Encounter%')
Show source
Register or log in to add new notes.