Auto refresh for expired content?

Francis Daly francis at
Wed May 17 15:52:54 UTC 2017

On Wed, May 17, 2017 at 03:29:03AM -0400, mkuehn wrote:

Hi there,

> proxy_cache_path /var/cache/nginx/spieldaten levels=1:2
> keys_zone=spieldaten:100m max_size=150m inactive=5d use_temp_path=off;
> ... ... ...
>             proxy_cache test;

I'm pretty sure that nginx's internationalisation/localisation efforts
don't allow it to recognise that "test" and "spieldaten" should be
considered equivalent :-)

That aside: the auto-refresh works for me.

Using your proxy_cache settings in a test nginx.conf:

http {
  server {
    listen 8880;
    return 200 "Now it is $time_local\n";
    access_log logs/upstream.log;

  proxy_cache_path /tmp/testcache levels=1 keys_zone=test:10m max_size=10m inactive=5d use_temp_path=off;

  server {
    listen 8080;
    proxy_cache test;
    proxy_cache_valid 200 302 1m;
    proxy_cache_valid 404 1m;
    proxy_cache_valid any 2m;
    proxy_ignore_headers X-Accel-Expires Expires Cache-Control;
    proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
    proxy_cache_lock on;
    proxy_cache_background_update on;

    access_log logs/main.log;
    location / {

I can do

$ while :; do date; curl; sleep 7; done

and the first request after the 1-minute expiry gives me the old content;
and the next request gives me the new content that was fetched 7 seconds

(And I can compare the different log files, to see how much my caching
saved the upstream port 8880 server from processing.)

Which seems to be exactly what you want.

Does that test work for you? If it does not, there is a problem to be
resolved. If it does, then you can start to compare your own system with
what is above, and spot the difference.

> Maybe you have an idea, why proxy_cache_background_update not working?

As above, it works for me. So - what is different in your system?

Good luck with it,

Francis Daly        francis at

More information about the nginx mailing list