Getting fastcgi_no_cache to cache the fresh response

I have been trying to find a good and standard way of invalidating nginx
fastcgi cache. Some time ago we had the fastcgi_cache_bypass filter
which was not completely implemented and didn’t work (and has been
removed from the wiki since). Now the only option seems to be
fastcgi_no_cache.

Is there a way to cache that fresh response from the backend when
fastcgi_no_cache is 1?

Like this:

  1. Nginx receives a request with fastcgi_no_cache 1
  2. Nginx skips cache and returns a fresh response from the backend
  3. Nginx stores that response in the cache
  4. All of the subsequent requests when fastcgi_no_cache 0 (with the same
    cache_key) return that latest cached response.

Kaspars

Posted at Nginx Forum: