<div dir="ltr"><span class="gmail-gI"><span>Hi,<br><br>I was checking how proxy_no_cache is handled, and I want to open a discussion<br>here. When it is set to off, should the ngx_http_upstream_cache[0] call at all? I<br>mean, why start the cache options when it's not enabled at all?<br><br>The primary use case is when the cache is disabled, and things regarding cache<br>are still in there like proxy_cache_convert_head, etc.. <br><br>I have a small patch about what I'm trying to do. Is it something that you will<br>accept at all?<br><br>[0] <a href="https://github.com/nginx/nginx/blob/5eadaf69e394c030056e4190d86dae0262f8617c/src/http/ngx_http_upstream.c#L823">https://github.com/nginx/nginx/blob/5eadaf69e394c030056e4190d86dae0262f8617c/src/http/ngx_http_upstream.c#L823</a> <br><br>Patch(Not complete at all)<br><br>diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c<br>index 61fad5ca..1217767d 100644<br>--- a/src/http/ngx_http_upstream.c<br>+++ b/src/http/ngx_http_upstream.c<br>@@ -566,42 +566,55 @@ ngx_http_upstream_init_request(ngx_http_request_t *r)<br> #if (NGX_HTTP_CACHE)<br> <br>     if (u->conf->cache) {<br>-        ngx_int_t  rc;<br> <br>-        rc = ngx_http_upstream_cache(r, u);<br>+      switch (ngx_http_test_predicates(r, u->conf->no_cache)) {<br> <br>-        if (rc == NGX_BUSY) {<br>-            r->write_event_handler = ngx_http_upstream_init_request;<br>-            return;<br>-        }<br>+      case NGX_ERROR:<br>+          return;<br> <br>-        r->write_event_handler = ngx_http_request_empty_handler;<br>+      case NGX_DECLINED:<br>+          /* No need to configure cache at all */<br>+          break;<br>+      default: {/* NGX_OK */<br>+          ngx_int_t  rc;<br>+          rc = ngx_http_upstream_cache(r, u);<br> <br>-        if (rc == NGX_ERROR) {<br>-            ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);<br>-            return;<br>-        }<br>+          if (rc == NGX_BUSY) {<br>+              r->write_event_handler = ngx_http_upstream_init_request;<br>+              return;<br>+          }<br> <br>-        if (rc == NGX_OK) {<br>-            rc = ngx_http_upstream_cache_send(r, u);<br>+          r->write_event_handler = ngx_http_request_empty_handler;<br> <br>-            if (rc == NGX_DONE) {<br>-                return;<br>-            }<br>+          if (rc == NGX_ERROR) {<br>+              ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);<br>+              return;<br>+          }<br> <br>-            if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) {<br>-                rc = NGX_DECLINED;<br>-                r->cached = 0;<br>-                u->buffer.start = NULL;<br>-                u->cache_status = NGX_HTTP_CACHE_MISS;<br>-                u->request_sent = 1;<br>-            }<br>-        }<br>+          if (rc == NGX_OK) {<br>+              rc = ngx_http_upstream_cache_send(r, u);<br>+<br>+              if (rc == NGX_DONE) {<br>+                  return;<br>+              }<br>+<br>+              if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) {<br>+                  rc = NGX_DECLINED;<br>+                  r->cached = 0;<br>+                  u->buffer.start = NULL;<br>+                  u->cache_status = NGX_HTTP_CACHE_MISS;<br>+                  u->request_sent = 1;<br>+              }<br>+          }<br>+<br>+          if (rc != NGX_DECLINED) {<br>+              ngx_http_finalize_request(r, rc);<br>+              return;<br>+          }<br>+          break;<br>+      }<br>+    }<br> <br>-        if (rc != NGX_DECLINED) {<br>-            ngx_http_finalize_request(r, rc);<br>-            return;<br>-        }<br>     }<br> <br> #endif<br></span></span></div>