<div dir="ltr"><div># HG changeset patch</div><div># User Thorvaldur Thorvaldsson <<a href="mailto:thorvaldur.thorvaldsson@gmail.com">thorvaldur.thorvaldsson@gmail.com</a>></div><div># Date 1450109082 -3600</div><div>#      Mon Dec 14 17:04:42 2015 +0100</div><div># Node ID e017db1282d4b8c4d541416e42fe7df8abc73302</div><div># Parent  def9c9c9ae05cfa7467b0ec96e76afa180c23dfb</div><div>Upstream: Cache "immediately stale" responses if revalidate is on.</div><div><br></div><div>Previously, the proxy cache would never store responses if max-age=0,</div><div>even when "proxy_cache_revalidate" was "on" and the response included an</div><div>ETag. This came as a surprise.</div><div><br></div><div>Now, a header like "Cache-Control: max-age=0, must-revalidate" can be</div><div>used to make nginx cache responses that always require revalidation,</div><div>like, when authorization is required (and cheap).</div><div><br></div><div>diff -r def9c9c9ae05 -r e017db1282d4 src/http/ngx_http_file_cache.c</div><div>--- a/src/http/ngx_http_file_cache.c<span class="" style="white-space:pre">     </span>Sat Dec 12 10:32:58 2015 +0300</div><div>+++ b/src/http/ngx_http_file_cache.c<span class="" style="white-space:pre"> </span>Mon Dec 14 17:04:42 2015 +0100</div><div>@@ -628,7 +628,7 @@</div><div> </div><div>     now = ngx_time();</div><div> </div><div>-    if (c->valid_sec < now) {</div><div>+    if (c->valid_sec <= now) {</div><div> </div><div>         ngx_shmtx_lock(&cache->shpool->mutex);</div><div> </div><div>@@ -831,7 +831,7 @@</div><div> </div><div>         if (fcn->error) {</div><div> </div><div>-            if (fcn->valid_sec < ngx_time()) {</div><div>+            if (fcn->valid_sec <= ngx_time()) {</div><div>                 goto renew;</div><div>             }</div><div> </div><div>diff -r def9c9c9ae05 -r e017db1282d4 src/http/ngx_http_upstream.c</div><div>--- a/src/http/ngx_http_upstream.c<span class="" style="white-space:pre">  </span>Sat Dec 12 10:32:58 2015 +0300</div><div>+++ b/src/http/ngx_http_upstream.c<span class="" style="white-space:pre">   </span>Mon Dec 14 17:04:42 2015 +0100</div><div>@@ -2819,7 +2819,7 @@</div><div>             }</div><div>         }</div><div> </div><div>-        if (valid) {</div><div>+        if (valid || r->upstream->conf->cache_revalidate) {</div><div>             r->cache->date = now;</div><div>             r->cache->body_start = (u_short) (u->buffer.pos - u->buffer.start);</div><div> </div><div>@@ -4272,7 +4272,7 @@</div><div>         return NGX_OK;</div><div>     }</div><div> </div><div>-    if (n == 0) {</div><div>+    if (n == 0 && !r->upstream->conf->cache_revalidate) {</div><div>         u->cacheable = 0;</div><div>         return NGX_OK;</div><div>     }</div><div>@@ -4312,7 +4312,9 @@</div><div> </div><div>     expires = ngx_parse_http_time(h->value.data, h->value.len);</div><div> </div><div>-    if (expires == NGX_ERROR || expires < ngx_time()) {</div><div>+    if (expires == NGX_ERROR</div><div>+        || (expires < ngx_time() && !r->upstream->conf->cache_revalidate))</div><div>+    {</div><div>         u->cacheable = 0;</div><div>         return NGX_OK;</div><div>     }</div><div>@@ -4356,7 +4358,9 @@</div><div> </div><div>         switch (n) {</div><div>         case 0:</div><div>-            u->cacheable = 0;</div><div>+            if (!r->upstream->conf->cache_revalidate) {</div><div>+                u->cacheable = 0;</div><div>+            }</div><div>             /* fall through */</div><div> </div><div>         case NGX_ERROR:</div><div><br></div></div>