查看源代码,caches_page
自动假定缓存文件的扩展名应该是它在路径包含句点 ( .
) 时找到的“扩展名”。这个逻辑实际上是另一种方法,page_cache_file
:
def page_cache_file(path, extension)
name = (path.empty? || path == "/") ? "/index" : URI.parser.unescape(path.chomp('/'))
unless (name.split('/').last || name).include? '.'
name << (extension || self.page_cache_extension)
end
return name
end
如果需要,您可能会覆盖此方法以在控制器中稍有不同的操作,或者使用默认的 ActionController::Base 实现。这是一个可能的例子:
class MyController < ApplicationController
class << self
private
# override the ActionController method
def page_cache_file(path, extension)
# use the default logic unless this is a /sites/:domainname request
# (may need to tweak the regex)
super unless path =~ %r{/sites/.*}
# otherwise customize logic to always include the extension
name = (path.empty? || path == "/") ? "/index" : URI.parser.unescape(path.chomp('/'))
name << (extension || self.page_cache_extension)
return name
end
end
end