comparison src/http/ngx_http_upstream.c @ 631:b6a5942a4e6a NGINX_0_8_46

nginx 0.8.46 *) Change: now the "proxy_no_cache", "fastcgi_no_cache", "uwsgi_no_cache", and "scgi_no_cache" directives affect on a cached response saving only. *) Feature: the "proxy_cache_bypass", "fastcgi_cache_bypass", "uwsgi_cache_bypass", and "scgi_cache_bypass" directives. *) Bugfix: nginx did not free memory in cache keys zones if there was an error during working with backend: the memory was freed only after inactivity time or on memory low condition.
author Igor Sysoev <http://sysoev.ru>
date Mon, 19 Jul 2010 00:00:00 +0400
parents 016632f0fb18
children cde3626b2d0d
comparison
equal deleted inserted replaced
630:913af46ee783 631:b6a5942a4e6a
631 631
632 c = r->cache; 632 c = r->cache;
633 633
634 if (c == NULL) { 634 if (c == NULL) {
635 635
636 if (u->conf->no_cache) { 636 switch (ngx_http_test_predicates(r, u->conf->cache_bypass)) {
637 rc = ngx_http_cache(r, u->conf->no_cache); 637
638 if (rc != NGX_OK) { 638 case NGX_ERROR:
639 return rc; 639 return NGX_ERROR;
640 } 640
641 case NGX_DECLINED:
642 u->cache_status = NGX_HTTP_CACHE_BYPASS;
643 return NGX_DECLINED;
644
645 default: /* NGX_OK */
646 break;
641 } 647 }
642 648
643 if (!(r->method & u->conf->cache_methods)) { 649 if (!(r->method & u->conf->cache_methods)) {
644 return NGX_DECLINED; 650 return NGX_DECLINED;
645 } 651 }
646 652
647 if (r->method & NGX_HTTP_HEAD) { 653 if (r->method & NGX_HTTP_HEAD) {
648 u->method = ngx_http_core_get_method; 654 u->method = ngx_http_core_get_method;
649 } 655 }
650 656
651 c = ngx_pcalloc(r->pool, sizeof(ngx_http_cache_t)); 657 if (ngx_http_file_cache_new(r) != NGX_OK) {
652 if (c == NULL) {
653 return NGX_ERROR; 658 return NGX_ERROR;
654 } 659 }
655
656 if (ngx_array_init(&c->keys, r->pool, 4, sizeof(ngx_str_t)) != NGX_OK) {
657 return NGX_ERROR;
658 }
659
660 r->cache = c;
661 c->file.log = r->connection->log;
662 660
663 if (u->create_key(r) != NGX_OK) { 661 if (u->create_key(r) != NGX_OK) {
664 return NGX_ERROR; 662 return NGX_ERROR;
665 } 663 }
666 664
667 /* TODO: add keys */ 665 /* TODO: add keys */
668 666
669 ngx_http_file_cache_create_key(r); 667 ngx_http_file_cache_create_key(r);
670 668
671 u->cacheable = 1; 669 u->cacheable = 1;
670
671 c = r->cache;
672 672
673 c->min_uses = u->conf->cache_min_uses; 673 c->min_uses = u->conf->cache_min_uses;
674 c->body_start = u->conf->buffer_size; 674 c->body_start = u->conf->buffer_size;
675 c->file_cache = u->conf->cache->data; 675 c->file_cache = u->conf->cache->data;
676 676
2096 if (r->cache && r->cache->file.fd != NGX_INVALID_FILE) { 2096 if (r->cache && r->cache->file.fd != NGX_INVALID_FILE) {
2097 ngx_pool_run_cleanup_file(r->pool, r->cache->file.fd); 2097 ngx_pool_run_cleanup_file(r->pool, r->cache->file.fd);
2098 r->cache->file.fd = NGX_INVALID_FILE; 2098 r->cache->file.fd = NGX_INVALID_FILE;
2099 } 2099 }
2100 2100
2101 switch (ngx_http_test_predicates(r, u->conf->no_cache)) {
2102
2103 case NGX_ERROR:
2104 ngx_http_upstream_finalize_request(r, u, 0);
2105 return;
2106
2107 case NGX_DECLINED:
2108 u->cacheable = 0;
2109 break;
2110
2111 default: /* NGX_OK */
2112
2113 if (u->cache_status == NGX_HTTP_CACHE_BYPASS) {
2114
2115 if (ngx_http_file_cache_new(r) != NGX_OK) {
2116 ngx_http_upstream_finalize_request(r, u, 0);
2117 return;
2118 }
2119
2120 if (u->create_key(r) != NGX_OK) {
2121 ngx_http_upstream_finalize_request(r, u, 0);
2122 return;
2123 }
2124
2125 /* TODO: add keys */
2126
2127 r->cache->min_uses = u->conf->cache_min_uses;
2128 r->cache->body_start = u->conf->buffer_size;
2129 r->cache->file_cache = u->conf->cache->data;
2130
2131 if (ngx_http_file_cache_create(r) != NGX_OK) {
2132 ngx_http_upstream_finalize_request(r, u, 0);
2133 return;
2134 }
2135
2136 u->cacheable = 1;
2137 }
2138
2139 break;
2140 }
2141
2101 if (u->cacheable) { 2142 if (u->cacheable) {
2102 time_t now, valid; 2143 time_t now, valid;
2103 2144
2104 now = ngx_time(); 2145 now = ngx_time();
2105 2146