instance method
cache_version
Ruby on Rails 6.1.7.10
Since v6.0.6Signature
cache_version(timestamp_column = :updated_at)
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%')
Parameters
-
timestamp_columnopt = :updated_at
Source
# File activerecord/lib/active_record/relation.rb, line 337
def cache_version(timestamp_column = :updated_at)
if collection_cache_versioning
@cache_versions ||= {}
@cache_versions[timestamp_column] ||= compute_cache_version(timestamp_column)
end
end
Defined in activerecord/lib/active_record/relation.rb line 337
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Relation