我在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?已提出类似问题 他们没有在答案中提供一个例子。
答案 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
应该这样做。