跳到內容 跳到搜尋
方法
F

實例公開的方法

fragment_cache_key(value = nil, &key)

讓你為快取片段指定控制器廣域金鑰字首。傳遞常數`值`或於產生快取金鑰時計算值的區塊。

舉例來說,你可能想使用全域版本識別碼為所有片段快取金鑰加上字首,這樣你就能輕鬆地使所有快取失效。

class ApplicationController
  fragment_cache_key "v1"
end

當需要使所有片段失效時,只要變更字串常數即可。或者使用計算值,逐步推出快取失效

class ApplicationController
  fragment_cache_key do
    @account.id.odd? ? "v1" : "v2"
  end
end
# File actionpack/lib/abstract_controller/caching/fragments.rb, line 58
def fragment_cache_key(value = nil, &key)
  self.fragment_cache_keys += [key || -> { value }]
end