My Rails application is running on a VM. The VM’s performance is just fine with static pages. In fact, I’m running another site using Apache virtual hosting that is just serving up static HTML files and the response is adequate. However, my Rails application that is dynamically generating XML files responds very slowly. In fact, it takes about 10 seconds or so for each XML file. These XML files that Rails generates do not change more than once a day.
What is the best practice to configure these XML files to be cached?
Edit 1:
I should mention that these XML files are not viewed by a browser. They are viewed by mobile applications in the ‘field.’ So, unfortunately sending ‘HTTP/1.0 304 not modified’ won’t work.
Edit 2:
If it matters, I’m using Phusion Passenger to host my Rails app.
If you’re using rails’ static page caching and serving through apache, just using an explicit xml extension on the urls would do it.
if you’re only serving xml and no html you might also edit the apache conf to default to xml instead of html when looking for cached files.
cache expiry is a rather boring thing to code and test, but since you’re seldom regenerating the files, you might just expire the entire cache.
Here’s a trimmed selection of files and excerpts from how I handle cache in a small, seldom updated rails site:
In the controllers you want to cache
In the controllers/actions that modify data that would cause changes to the xmls:
In ‘config/environments/production.rb’
Somehere in your vhost apache conf:
The dumb sweeper that cleans that entire cache every time it’s triggered:
lib/tasks/cache.rakeIf you prefer to default the default implied extension to xml, change the extension on the 1.4.2 index rule, and the following:
to: