Expiring an entire page cache tree atomically 16 Nov 09
As you’ll all know, Rails has page caching baked right in – the first time an action is hit, it writes a html file of the result to the filesystem. Subsequent hits are served direct from the html file at high speed by the web server without ever involving your Rails app.
Expiring the cache is just a case of deleting the html file. But what if you want to expire an entire tree of cache files? Say you change something in a header or footer, so every single page needs expiring at once.
The usual way to do this is to just delete the entire page cache tree, with FileUtils.rm_rf. This works pretty well, but with a big tree you’ll get strange behaviour under high load due to concurrent access. Whilst your rm_rf process is deleting the tree, file by file, your webserver will still be looking in there for page cache files and Rails will still be trying to write them.
Read the rest of this entry »