Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a web service that takes a while to build a response despite being tuned as best I can.

What I'd like is some sort of cache sitting in front of the service which would always return the last known value from the service, but at the same time pass the request back to the service to build an up to date response for the next request.

I'm aware of the limitations that this puts on the freshness of the data, but you can assume that I'm happy to live with that.

The technologies I'm using at present are python uwsgi via nginx, but that need not be a limit to any solution you might suggest.


share|improve this question
up vote 2 down vote accepted

Assuming you want a reverse proxy you can use Varnish in saint mode or squid with stale-if-error directive.

If you want in-app cache, using memcached for example, just don't rely on storage expiry mechanism - store expiry with cached object array(cached_object=>object, expiry=>timestamp) and react if you encounter stale cache: increase expiry to now + a bit of time (to prevent dogpiling - multiple processes regenerating cache in parallel), use stale cache, initialize update.

share|improve this answer
That Memcache solution looks like I can make it work. Thanks, FYI NGinX has proxy_cache_use_stale which I get the impression might also have been usable, but couldn't quite figure out how. Cheers. – Col Wilson Jun 28 '12 at 21:28
AFAIK all you need is proxy_cache_use_stale updating; and is should just work. – c2h5oh Jun 28 '12 at 21:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.