3 ms·
we use this exact approach to generate all of our blog pages. incredibly efficient. the twist we use to handle race conditions is to create a lock file. if the
by drusenko 17y ago
we use this exact approach to generate all of our blog pages. incredibly efficient.
the twist we use to handle race conditions is to create a lock file. if the 404 handler is called and the lock file exists, someone else is generating that page as we speak -- it goes into a timed loop to check for the file being available. when found, it serves it directly with the 200 header, like you mentioned.
we have a maximum loop value (a second, i think) -- if you hit that, it means the other process died for some reason, and never deleted the lock or the page. in that case, generate and write the page yourself, and remove the lock. all future requests are served off of the file system.
one nice part of this caching mechanism is that to remove the cache, you just rm -rf the blog directory. tada!