instance method fragment_cache_key

Ruby on Rails 6.0.6

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

fragment_cache_key(value = nil, &key)

Allows you to specify controller-wide key prefixes for cache fragments. Pass either a constant value, or a block which computes a value each time a cache key is generated.

For example, you may want to prefix all fragment cache keys with a global version identifier, so you can easily invalidate all caches.

class ApplicationController
  fragment_cache_key "v1"
end

When it’s time to invalidate all fragments, simply change the string constant. Or, progressively roll out the cache invalidation using a computed value:

class ApplicationController
  fragment_cache_key do
    @account.id.odd? ? "v1" : "v2"
  end
end

Parameters

value opt = nil
key block
Source
# File actionpack/lib/abstract_controller/caching/fragments.rb, line 57
        def fragment_cache_key(value = nil, &key)
          self.fragment_cache_keys += [key || -> { value }]
        end

Defined in actionpack/lib/abstract_controller/caching/fragments.rb line 57 · View on GitHub · Improve this page · Find usages on GitHub

Defined in AbstractController::Caching::Fragments::ClassMethods

Type at least 2 characters to search.

↑↓ navigate · open · esc close