instance method cache_version

Ruby on Rails 8.0.4

Since v5.2.8.1

Available in: v5.2.8.1 v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

cache_version()

Returns a cache version that can be used together with the cache key to form a recyclable caching scheme. By default, the #updated_at column is used for the cache_version, but this method can be overwritten to return something else.

Note, this method will return nil if ActiveRecord::Base.cache_versioning is set to false.

Source
# File activerecord/lib/active_record/integration.rb, line 97
    def cache_version
      return unless cache_versioning

      if has_attribute?("updated_at")
        timestamp = updated_at_before_type_cast
        if can_use_fast_cache_version?(timestamp)
          raw_timestamp_to_cache_version(timestamp)

        elsif timestamp = updated_at
          timestamp.utc.to_fs(cache_timestamp_format)
        end
      elsif self.class.has_attribute?("updated_at")
        raise ActiveModel::MissingAttributeError, "missing attribute 'updated_at' for #{self.class}"
      end
    end

Defined in activerecord/lib/active_record/integration.rb line 97 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveRecord::Integration

Type at least 2 characters to search.

↑↓ navigate · open · esc close