当调用清理器时,Rails 不会删除 cache/.html 页面
我在 Rails 中的 Sweepers 和缓存方面遇到了一些问题。
/cache 中的 .html 文件是在第一次查看时生成的。
Sweeper 操作在需要时被调用。
但是,sweeper 操作不会从 /cache 中删除 .html 页面
。下面的代码是从我的 /controllers 和 /sweepers 目录中删除的。 puts 行都记录了这两个日志,所以我知道我们执行得很好——expire 命令似乎并没有删除该文件。
有人知道我可以在哪里看吗?
class WidgetsController < ApplicationController
cache_sweeper :widget_sweeper
caches_page :help
def help
render :template => '/widgets/help.html'
end
end
class WidgetSweeper < ActionController::Caching::Sweeper
observe HelpPage
def after_save(record)
puts "record "
puts record.inspect
expire_page(:controller => 'widgets', :action => 'help')
puts "ok!"
end
end
I'm having some issues with Sweepers and Caching in Rails.
The .html file in /cache is being generated on first view.
The Sweeper action is being called when needed.
However, the sweeper action is not deleting the .html page from /cache
The code below is stripped down from my /controllers and /sweepers directory. the puts
lines both log, so I know that we're executing fine -- the expire command just doesn't seem to delete the file.
anyone have an idea where i can lool ?
class WidgetsController < ApplicationController
cache_sweeper :widget_sweeper
caches_page :help
def help
render :template => '/widgets/help.html'
end
end
class WidgetSweeper < ActionController::Caching::Sweeper
observe HelpPage
def after_save(record)
puts "record "
puts record.inspect
expire_page(:controller => 'widgets', :action => 'help')
puts "ok!"
end
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只是通过在控制台中操作一些 HelpPage 记录来测试这一点吗?看来您必须影响控制器中的更改。
我使用您上面提供的代码制作了一个测试应用程序,并在启用缓存的情况下运行它。我在 Rails 控制台中创建了一些新的 HelpPage 记录,并且收到了两条日志消息,但没有页面过期。
但是,当我在控制器中创建新的 HelpPage 时,我确实按预期获得了页面过期时间。
Are you just testing this by manipulating some HelpPage records in the console? It looks like you have to affect the changes in a controller.
I made a test app using the code you supplied above and ran it with caching enabled. I created some new HelpPage records in the rails console, and I got the two log messages but no page expiration.
However, when I created a new HelpPage in a controller, I did get the page expiration as expected.