views:

478

answers:

2

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.

A: 

If you just need to regenerate the page every couple days whenever should do the job.

ez
if the page is cached, then how do I regenerate it without expiring it first?
concept47
can you tell us how/where do you generate your sitemap? a little code will help
ez
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
+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
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
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
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
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
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
@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