]> git.kaiwu.me - nginx.git/commitdiff
do not create cache key in AIO invocation
authorIgor Sysoev <igor@sysoev.ru>
Fri, 28 Aug 2009 11:23:50 +0000 (11:23 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Fri, 28 Aug 2009 11:23:50 +0000 (11:23 +0000)
src/http/ngx_http_upstream.c

index 6dcebd0a5843449cc4bf0eb5312da1ff60fe842b..9aa797ac06cbeca732543daca1623dd91a8bf653 100644 (file)
@@ -380,6 +380,10 @@ ngx_http_upstream_create(ngx_http_request_t *r)
     u->peer.lock = &r->connection->lock;
 #endif
 
+#if (NGX_HTTP_CACHE)
+    r->cache = NULL;
+#endif
+
     return NGX_OK;
 }
 
@@ -607,41 +611,46 @@ ngx_http_upstream_cache(ngx_http_request_t *r, ngx_http_upstream_t *u)
     ngx_int_t          rc;
     ngx_http_cache_t  *c;
 
-    if (!(r->method & u->conf->cache_methods)) {
-        return NGX_DECLINED;
-    }
-
-    if (r->method & NGX_HTTP_HEAD) {
-        u->method = ngx_http_core_get_method;
-    }
+    c = r->cache;
 
-    c = ngx_pcalloc(r->pool, sizeof(ngx_http_cache_t));
     if (c == NULL) {
-        return NGX_ERROR;
-    }
 
-    if (ngx_array_init(&c->keys, r->pool, 4, sizeof(ngx_str_t)) != NGX_OK) {
-        return NGX_ERROR;
-    }
+        if (!(r->method & u->conf->cache_methods)) {
+            return NGX_DECLINED;
+        }
 
-    r->cache = c;
-    c->file.log = r->connection->log;
+        if (r->method & NGX_HTTP_HEAD) {
+            u->method = ngx_http_core_get_method;
+        }
 
-    if (u->create_key(r) != NGX_OK) {
-        return NGX_ERROR;
-    }
+        c = ngx_pcalloc(r->pool, sizeof(ngx_http_cache_t));
+        if (c == NULL) {
+            return NGX_ERROR;
+        }
 
-    /* TODO: add keys */
+        if (ngx_array_init(&c->keys, r->pool, 4, sizeof(ngx_str_t)) != NGX_OK) {
+            return NGX_ERROR;
+        }
 
-    ngx_http_file_cache_create_key(r);
+        r->cache = c;
+        c->file.log = r->connection->log;
 
-    u->cacheable = 1;
+        if (u->create_key(r) != NGX_OK) {
+            return NGX_ERROR;
+        }
+
+        /* TODO: add keys */
 
-    c->min_uses = u->conf->cache_min_uses;
-    c->body_start = u->conf->buffer_size;
-    c->file_cache = u->conf->cache->data;
+        ngx_http_file_cache_create_key(r);
 
-    u->cache_status = NGX_HTTP_CACHE_MISS;
+        u->cacheable = 1;
+
+        c->min_uses = u->conf->cache_min_uses;
+        c->body_start = u->conf->buffer_size;
+        c->file_cache = u->conf->cache->data;
+
+        u->cache_status = NGX_HTTP_CACHE_MISS;
+    }
 
     rc = ngx_http_file_cache_open(r);