page_cache_directory gotcha

Posted by bitbutter on September 13, 2007

Lately I started my long overdue experiments with caching. I had some difficulty confirming to myself that rails page caching was working. Following fingertips lazy sweeping article (check it if you didn't already it's can be very handy) I had configured my application to store cache files in public/cache instead of public. The fingertips technique results in the deletion of the contents of the cache folder when doing its 'sweeping' so it's important that this isn't the public folder itself.

Running the application locally (in production mode) the cache files were being generated correctly, but weren't being served back the next time the page was accessed. Eventually it became clear why this was happening. Although I'd modified the public/.htaccess rewrite rules so that apache would know where to find the new cache directory, I wasn't running Apache locally so when I tested this on my own machine the cached files were ignored, and regenerated on each request.

So far I haven't figured out how to configure mongrel to look in the correct place for the cached files but this isn't so pressing since caching does work as expected on the production server.

For anyone in a similar position; to confirm that pages you're seeing in your browser are being served from a cached file (rather than being generated dynamically) cd into your application directory and tail the log file corresponding to the environment your app is running in:

tail -f 100 log/production.log

Then access the page in question with your browser and watch the terminal. Accessing cached pages should bypass rails completely meaning that no new output should show up in the terminal.

Rails Envy Caching Tutorial

Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

Comments