Mercurial > hg > nginx
comparison src/http/ngx_http_upstream.c @ 6906:1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
The directives enable cache updates in subrequests.
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Fri, 10 Feb 2017 15:13:41 +0300 |
parents | 9a9e13686869 |
children | 5850fed24639 |
comparison
equal
deleted
inserted
replaced
6905:9a9e13686869 | 6906:1aeaae6e9446 |
---|---|
15 ngx_http_upstream_t *u); | 15 ngx_http_upstream_t *u); |
16 static ngx_int_t ngx_http_upstream_cache_get(ngx_http_request_t *r, | 16 static ngx_int_t ngx_http_upstream_cache_get(ngx_http_request_t *r, |
17 ngx_http_upstream_t *u, ngx_http_file_cache_t **cache); | 17 ngx_http_upstream_t *u, ngx_http_file_cache_t **cache); |
18 static ngx_int_t ngx_http_upstream_cache_send(ngx_http_request_t *r, | 18 static ngx_int_t ngx_http_upstream_cache_send(ngx_http_request_t *r, |
19 ngx_http_upstream_t *u); | 19 ngx_http_upstream_t *u); |
20 static ngx_int_t ngx_http_upstream_cache_background_update( | |
21 ngx_http_request_t *r, ngx_http_upstream_t *u); | |
20 static ngx_int_t ngx_http_upstream_cache_check_range(ngx_http_request_t *r, | 22 static ngx_int_t ngx_http_upstream_cache_check_range(ngx_http_request_t *r, |
21 ngx_http_upstream_t *u); | 23 ngx_http_upstream_t *u); |
22 static ngx_int_t ngx_http_upstream_cache_status(ngx_http_request_t *r, | 24 static ngx_int_t ngx_http_upstream_cache_status(ngx_http_request_t *r, |
23 ngx_http_variable_value_t *v, uintptr_t data); | 25 ngx_http_variable_value_t *v, uintptr_t data); |
24 static ngx_int_t ngx_http_upstream_cache_last_modified(ngx_http_request_t *r, | 26 static ngx_int_t ngx_http_upstream_cache_last_modified(ngx_http_request_t *r, |
576 | 578 |
577 if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) { | 579 if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) { |
578 rc = NGX_DECLINED; | 580 rc = NGX_DECLINED; |
579 r->cached = 0; | 581 r->cached = 0; |
580 } | 582 } |
583 | |
584 if (ngx_http_upstream_cache_background_update(r, u) != NGX_OK) { | |
585 rc = NGX_ERROR; | |
586 } | |
581 } | 587 } |
582 | 588 |
583 if (rc != NGX_DECLINED) { | 589 if (rc != NGX_DECLINED) { |
584 ngx_http_finalize_request(r, rc); | 590 ngx_http_finalize_request(r, rc); |
585 return; | 591 return; |
867 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 873 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
868 "http upstream cache: %i", rc); | 874 "http upstream cache: %i", rc); |
869 | 875 |
870 switch (rc) { | 876 switch (rc) { |
871 | 877 |
878 case NGX_HTTP_CACHE_STALE: | |
879 | |
880 if (((u->conf->cache_use_stale & NGX_HTTP_UPSTREAM_FT_UPDATING) | |
881 || c->stale_updating) && !r->cache_updater | |
882 && u->conf->cache_background_update) | |
883 { | |
884 r->cache->background = 1; | |
885 u->cache_status = rc; | |
886 rc = NGX_OK; | |
887 } | |
888 | |
889 break; | |
890 | |
872 case NGX_HTTP_CACHE_UPDATING: | 891 case NGX_HTTP_CACHE_UPDATING: |
873 | 892 |
874 if ((u->conf->cache_use_stale & NGX_HTTP_UPSTREAM_FT_UPDATING) | 893 if (((u->conf->cache_use_stale & NGX_HTTP_UPSTREAM_FT_UPDATING) |
875 || c->stale_updating) | 894 || c->stale_updating) && !r->cache_updater) |
876 { | 895 { |
877 u->cache_status = rc; | 896 u->cache_status = rc; |
878 rc = NGX_OK; | 897 rc = NGX_OK; |
879 | 898 |
880 } else { | 899 } else { |
1040 /* rc == NGX_HTTP_UPSTREAM_INVALID_HEADER */ | 1059 /* rc == NGX_HTTP_UPSTREAM_INVALID_HEADER */ |
1041 | 1060 |
1042 /* TODO: delete file */ | 1061 /* TODO: delete file */ |
1043 | 1062 |
1044 return rc; | 1063 return rc; |
1064 } | |
1065 | |
1066 | |
1067 static ngx_int_t | |
1068 ngx_http_upstream_cache_background_update(ngx_http_request_t *r, | |
1069 ngx_http_upstream_t *u) | |
1070 { | |
1071 ngx_http_request_t *sr; | |
1072 | |
1073 if (!r->cached || !r->cache->background) { | |
1074 return NGX_OK; | |
1075 } | |
1076 | |
1077 if (ngx_http_subrequest(r, &r->uri, &r->args, &sr, NULL, | |
1078 NGX_HTTP_SUBREQUEST_CLONE) | |
1079 != NGX_OK) | |
1080 { | |
1081 return NGX_ERROR; | |
1082 } | |
1083 | |
1084 sr->header_only = 1; | |
1085 sr->cache_updater = 1; | |
1086 | |
1087 return NGX_OK; | |
1045 } | 1088 } |
1046 | 1089 |
1047 | 1090 |
1048 static ngx_int_t | 1091 static ngx_int_t |
1049 ngx_http_upstream_cache_check_range(ngx_http_request_t *r, | 1092 ngx_http_upstream_cache_check_range(ngx_http_request_t *r, |