如何从cron schedule强制片段缓存在rails上?

时间:2009-12-15 13:11:07

标签: ruby-on-rails caching cron

有没有什么方法可以触发页面进行片段缓存而无需第一次加载页面?

我打算使用cron schedule,这是因为我的cron调度程序更新了数据库,那时我想强制片段缓存发生。

2 个答案:

答案 0 :(得分:0)

这是一个原始的解决方案,但你总是可以让cron触发对你网页的网址的卷曲请求。

答案 1 :(得分:0)

我在后台工作程序中运行了以下代码。它在您的代码中实例化控制器,然后根据需要呈现视图并填充缓存。

cache_controller = PageController.new
cache_controller.response = Hashie::Mash.new({"content_type"=>"text/js"})
cache_controller.request = Hashie::Mash.new({"action"=>"show", "negotiate_mime"=>"js", "content_type"=>"application/x-www-form-urlencoded", "get?" => true})
cache_controller.params = {id: 1}
cache_controller.action_name = 'show'
cache_controller.show  # this is the method on controller you want to call.

在我的情况下,我正在点击js.erb,因此在您的示例中可能不需要某些内容。