我目前的解决方法是启用perform_caching
然后重新加载控制器:
class ProjectsCachingTest < ActionController::IntegrationTest
def setup
# force the controller to be reloaded when caching is enabled
ActionController::Base.perform_caching = true
load "projects_controller.rb"
end
def teardown
# undo the actions above
ActionController::Base.perform_caching = false
load "projects_controller.rb"
end
end
在最新版本的Rails 2中,遇到的问题与类方法caches_action
和caches_page
有关。他们都创建了一个环绕过滤器来执行缓存,但只有在启用perform_caching
时才会执行缓存。
因此,在运行时修改perform_caching
不会重新创建期望的过滤器。上面的例子是强制你的控制器重新评估的一种方法。
我想在Rails 3.1.8中使用它,它似乎不工作。每次请求都会重新生成页面。 – 2012-10-09 09:25:56