2010-12-19 37 views
1

我使用HTTP緩存在Heroku:要求:用cron頁面更新緩存

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? 處詢問過類似問題他們沒有提供答案中的示例。

回答

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 

這應該做到這一點。