请求包含cron的页面以更新缓存

时间:2010-12-19 14:28:02

标签: ruby-on-rails heroku

我在Heroku上使用http缓存:

def homepage
  response.headers['Cache-Control'] = 'public, max-age=86340'
  ...
end

我还添加了Heroku的免费cron插件:

desc "This task is called by the Heroku cron add-on"
task :cron => :environment do
 if Time.now.hour == 0 # run at midnight
   # I want to request a page here
 end
end

你能告诉我在申请页面时我应该把这个文件放进去吗?

How to force fragment cache on rails from cron schedule?已提出类似问题 他们没有在答案中提供一个例子。

1 个答案:

答案 0 :(得分:2)

require 'uri'
require 'net/http'

desc "This task is called by the Heroku cron add-on"
task :cron => :environment do
 if Time.now.hour == 0 # run at midnight
   uri = URI.parse('http://my-app.heroku.com/page')
   Net::HTTP.get(uri)
 end
end

应该这样做。