Archive for August, 2009

Return a file with Nginx based on its freshness

In previous posts we talked about Nginx, that excellent lightweight web server made in Russia. Nginx is powering the Visualizeus servers since day one.

The other day I was needing some feature on Nginx. In Visualizeus there’s a file cache for some things, like the feeds and so on. Till now if the requested url has a cached version, then Nginx returned it with no more questions. If not, then Nginx transfer the request to the backend, which generates a new cached version in disk for the following requests for that resource. Pretty normal.

But Nginx wasn’t aware of the freshness of the file at all, it only understands that easy logic: file exists, then return it. So to avoid stale cache it’s obvious we need to delete from time to time that cached resources. When to delete it depends on the type of object we’re caching, of course. For example, the feeds are deleted each time a new image appears in that feed, and so on. But it was a little bit cumbersome for some objects, like the image pages, where you don’t have a clear condition that makes the page stale. It needs some cron tasks to run periodically and find files older than X, and those tasks eats a lot of resources specially when we’re talking of thousands and thousands of files and folders. So it was clear a better solution was needed here.
(more…)

August 21st, 2009 | Development, English | Wanna say something?

Categories

Syndication

my favorite pictures

    Archives

    Cerrar
    Enviar por Correo