Alteroot:~# 01 Oct 2014 on The problem : be able to cache a backend response if it took more than 5 seconds. If not, don't cache it! A good challenge from @florentsolt . He solves the problem with a nodejs reverse proxy behind nginx, but I prefer a pure nginx implementation ;) I needed that kind of configuration as a temporary workaround due to a proprietary backend which responds slowly to certain request, and quickly to anothers. So instead of let the client wait 10 seconds or more, it's better to render a cached response for next clients for 60 seconds, even if it's not the more up to date data. Finding no informations on the subject, here's my solution (maybe not the better, but it worked for my needs). If you have a better solution (even with another software), you can add a comment :). I use the "map" directive to set a variable and pass it via the X-Accel-Expires...