I am generating a big sitemap for a site and using page caching on it, so that a sitemap.xml is generated in my public folder.
Is there a way to have this page expire after say 3.days?
I've looked but couldn't find anything that could do that.
views:
478answers:
2
A:
If you just need to regenerate the page every couple days whenever should do the job.
ez
2009-08-27 14:12:04
if the page is cached, then how do I regenerate it without expiring it first?
concept47
2009-08-27 16:53:43
can you tell us how/where do you generate your sitemap? a little code will help
ez
2009-08-27 17:51:07
Its just a rails controller action pulling in categories, products and spitting out an xml view (sitemap.xml.erb). Let me know if there's something specific you need to know.
concept47
2009-08-28 19:46:06
+2
A:
Set up a cron job to delete it:
cd /home/user/apps/myapp/current/public/ && rm sitemap.xml
If you use Whenever this should do the trick:
every 3.days, :at => '1:00am' do
command "cd /home/user/apps/myapp/current/public/ && rm sitemap.xml"
end
If you want to regenerate the file immediately add the following:
&& curl http://www.example.com/sitemap.xml
Roger Ertesvag
2009-08-27 14:47:58
I was trying to avoid this, since I have to write another job to hit the page and regenerate it anyway.So I was trying to just have one job instead of two.
concept47
2009-08-27 16:55:18
Not sure what kind of job your talking about, if you are using page caching the cached file is generated when someone tries to access it and it does not exist. And once the cached file has been created that rails action won't be run again until the file is deleted.
Roger Ertesvag
2009-08-27 19:34:39
I've been unclear ... my bad. This is a google sitemap, so the only things that will be hitting it are bots. The problem is that if the page takes too long to load, they won't use it. (I do work for an SEO client, this is what they tell me). So I'm going to have a cron job to just wget, the page every 3 days or so, but I need the cached xml page to be deleted so that a new sitemap is generated (the links on it change pretty often). Hope this is more clear.
concept47
2009-08-28 19:44:00
maybe i m missing something here, but can you just have the cron job run every 3 days and do 1) delete the xml file, 2) visit the /site/sitemap.xml(if i understand right, this will trigger the controller to generate the new xml)
ez
2009-08-28 20:37:52
You can use curl to fetch the file so that it is generated. I have updated the answer with the command to do this.
Roger Ertesvag
2009-08-29 09:41:37
@ez. I. know. this. But as per my question, I really would like to just know if there is another way (specifically some way in code or via plugin to expire page caches). I hope thats okay ;)
concept47
2009-08-29 10:27:09