Apache/Rails and Passenger Caching

1 view
Skip to first unread message

Mike Papper

unread,
Nov 20, 2009, 4:36:04 PM11/20/09
to Phusion Passenger Discussions
We are running a web site that has a large number of cached pages
which are normally served by Apache. In Rails fashion, the pages are
generated by rails when the cached version does not exist on disk (via
regular Apache rewrite rules and passengers built-in smarts).

One problem is that right after a deploy there are no cached pages and
there server appears (to end users) to be slow. A related issue is
that by allowing Apache to serve static pages throughout (most of) the
deploy and have access to the static cached content right after a
deploy, the deploy could be done at peak times/could be done safely
and with confidence/could be done at greater and greater frequencies.

I thought of this mechanism to kind of have my cake and eat it too...

1) make the cache directory a link so it is preserved between
deployments
2) Mark the timestamp at deploy. Use this to determine if we need to
regenerate the cached file (see next).
3) When a request comes in, if the cached file exists but is before
the deploy time, serve from cache but ALSO have mongrel serve the
request (and thus create a new version of the cached file).

There is one gotcha that can be avoided: when we serve an 'stale'
cached file (one whos timestamp is before deploy) the html will assume
the original CSS and javascripts whereas the request made by the
browser will get the new versions of these. This isnt a problem in
many cases but you could envision where it would be incorrect.

One way to get around the above issue is to put version numbers on the
CSS and JS files, such as application_7658436.js (i..e, the filename
is timestamped).

-------------
Any ideas how hard this would be to add to Passenger?
Any ideas of whether an Apache rewrite rule can take into account a
files modification time?

More importantly, does nayone have an opinion on how viable and useful
this would be?

Mike
Reply all
Reply to author
Forward
0 new messages