Proxy_no_cache question
Eloy Coto Pereiro
ecotoper at redhat.com
Thu Jun 3 08:12:50 UTC 2021
Hi,
I was checking how proxy_no_cache is handled, and I want to open a
discussion
here. When it is set to off, should the ngx_http_upstream_cache[0] call at
all? I
mean, why start the cache options when it's not enabled at all?
The primary use case is when the cache is disabled, and things regarding
cache
are still in there like proxy_cache_convert_head, etc..
I have a small patch about what I'm trying to do. Is it something that you
will
accept at all?
[0]
https://github.com/nginx/nginx/blob/5eadaf69e394c030056e4190d86dae0262f8617c/src/http/ngx_http_upstream.c#L823
Patch(Not complete at all)
diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
index 61fad5ca..1217767d 100644
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -566,42 +566,55 @@ ngx_http_upstream_init_request(ngx_http_request_t *r)
#if (NGX_HTTP_CACHE)
if (u->conf->cache) {
- ngx_int_t rc;
- rc = ngx_http_upstream_cache(r, u);
+ switch (ngx_http_test_predicates(r, u->conf->no_cache)) {
- if (rc == NGX_BUSY) {
- r->write_event_handler = ngx_http_upstream_init_request;
- return;
- }
+ case NGX_ERROR:
+ return;
- r->write_event_handler = ngx_http_request_empty_handler;
+ case NGX_DECLINED:
+ /* No need to configure cache at all */
+ break;
+ default: {/* NGX_OK */
+ ngx_int_t rc;
+ rc = ngx_http_upstream_cache(r, u);
- if (rc == NGX_ERROR) {
- ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
+ if (rc == NGX_BUSY) {
+ r->write_event_handler = ngx_http_upstream_init_request;
+ return;
+ }
- if (rc == NGX_OK) {
- rc = ngx_http_upstream_cache_send(r, u);
+ r->write_event_handler = ngx_http_request_empty_handler;
- if (rc == NGX_DONE) {
- return;
- }
+ if (rc == NGX_ERROR) {
+ ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
+ return;
+ }
- if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) {
- rc = NGX_DECLINED;
- r->cached = 0;
- u->buffer.start = NULL;
- u->cache_status = NGX_HTTP_CACHE_MISS;
- u->request_sent = 1;
- }
- }
+ if (rc == NGX_OK) {
+ rc = ngx_http_upstream_cache_send(r, u);
+
+ if (rc == NGX_DONE) {
+ return;
+ }
+
+ if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) {
+ rc = NGX_DECLINED;
+ r->cached = 0;
+ u->buffer.start = NULL;
+ u->cache_status = NGX_HTTP_CACHE_MISS;
+ u->request_sent = 1;
+ }
+ }
+
+ if (rc != NGX_DECLINED) {
+ ngx_http_finalize_request(r, rc);
+ return;
+ }
+ break;
+ }
+ }
- if (rc != NGX_DECLINED) {
- ngx_http_finalize_request(r, rc);
- return;
- }
}
#endif
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20210603/2b8658c8/attachment-0001.htm>
More information about the nginx-devel
mailing list