mirror of
https://github.com/nginx/nginx.git
synced 2026-08-04 14:58:20 +00:00
Merge 82459d8451 into 4b90ec7692
This commit is contained in:
commit
2b3a5db052
3 changed files with 50 additions and 30 deletions
|
|
@ -32,7 +32,7 @@
|
|||
|
||||
typedef struct {
|
||||
ngx_uint_t status;
|
||||
time_t valid;
|
||||
ngx_msec_t valid;
|
||||
} ngx_http_cache_valid_t;
|
||||
|
||||
|
||||
|
|
@ -196,7 +196,8 @@ void ngx_http_file_cache_update(ngx_http_request_t *r, ngx_temp_file_t *tf);
|
|||
void ngx_http_file_cache_update_header(ngx_http_request_t *r);
|
||||
ngx_int_t ngx_http_cache_send(ngx_http_request_t *);
|
||||
void ngx_http_file_cache_free(ngx_http_cache_t *c, ngx_temp_file_t *tf);
|
||||
time_t ngx_http_file_cache_valid(ngx_array_t *cache_valid, ngx_uint_t status);
|
||||
ngx_msec_t ngx_http_file_cache_valid(ngx_array_t *cache_valid,
|
||||
ngx_uint_t status);
|
||||
|
||||
char *ngx_http_file_cache_set_slot(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||
void *conf);
|
||||
|
|
|
|||
|
|
@ -545,8 +545,9 @@ ngx_http_file_cache_read(ngx_http_request_t *r, ngx_http_cache_t *c)
|
|||
u_char *p;
|
||||
time_t now;
|
||||
ssize_t n;
|
||||
ngx_str_t *key;
|
||||
ngx_int_t rc;
|
||||
ngx_str_t *key;
|
||||
ngx_time_t *tp;
|
||||
ngx_uint_t i;
|
||||
ngx_http_file_cache_t *cache;
|
||||
ngx_http_file_cache_header_t *h;
|
||||
|
|
@ -650,8 +651,11 @@ ngx_http_file_cache_read(ngx_http_request_t *r, ngx_http_cache_t *c)
|
|||
}
|
||||
|
||||
now = ngx_time();
|
||||
tp = ngx_timeofday();
|
||||
|
||||
if (c->valid_sec < now) {
|
||||
if (c->valid_sec < now
|
||||
|| (c->valid_sec == now && c->valid_msec <= tp->msec))
|
||||
{
|
||||
c->stale_updating = c->valid_sec + c->updating_sec >= now;
|
||||
c->stale_error = c->valid_sec + c->error_sec >= now;
|
||||
|
||||
|
|
@ -900,8 +904,14 @@ ngx_http_file_cache_exists(ngx_http_file_cache_t *cache, ngx_http_cache_t *c)
|
|||
}
|
||||
|
||||
if (fcn->error) {
|
||||
ngx_time_t *tp;
|
||||
|
||||
if (fcn->valid_sec < ngx_time()) {
|
||||
tp = ngx_timeofday();
|
||||
|
||||
if (fcn->valid_sec < tp->sec
|
||||
|| (fcn->valid_sec == tp->sec
|
||||
&& fcn->valid_msec <= tp->msec))
|
||||
{
|
||||
goto renew;
|
||||
}
|
||||
|
||||
|
|
@ -2349,7 +2359,7 @@ ngx_http_file_cache_set_watermark(ngx_http_file_cache_t *cache)
|
|||
}
|
||||
|
||||
|
||||
time_t
|
||||
ngx_msec_t
|
||||
ngx_http_file_cache_valid(ngx_array_t *cache_valid, ngx_uint_t status)
|
||||
{
|
||||
ngx_uint_t i;
|
||||
|
|
@ -2728,9 +2738,9 @@ ngx_http_file_cache_valid_set_slot(ngx_conf_t *cf, ngx_command_t *cmd,
|
|||
{
|
||||
char *p = conf;
|
||||
|
||||
time_t valid;
|
||||
ngx_str_t *value;
|
||||
ngx_int_t status;
|
||||
ngx_str_t *value;
|
||||
ngx_msec_t valid;
|
||||
ngx_uint_t i, n;
|
||||
ngx_array_t **a;
|
||||
ngx_http_cache_valid_t *v;
|
||||
|
|
@ -2748,8 +2758,8 @@ ngx_http_file_cache_valid_set_slot(ngx_conf_t *cf, ngx_command_t *cmd,
|
|||
value = cf->args->elts;
|
||||
n = cf->args->nelts - 1;
|
||||
|
||||
valid = ngx_parse_time(&value[n], 1);
|
||||
if (valid == (time_t) NGX_ERROR) {
|
||||
valid = ngx_parse_time(&value[n], 0);
|
||||
if (valid == (ngx_msec_t) NGX_ERROR) {
|
||||
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
||||
"invalid time value \"%V\"", &value[n]);
|
||||
return NGX_CONF_ERROR;
|
||||
|
|
|
|||
|
|
@ -2861,8 +2861,9 @@ ngx_http_upstream_test_next(ngx_http_request_t *r, ngx_http_upstream_t *u)
|
|||
&& u->cache_status == NGX_HTTP_CACHE_EXPIRED
|
||||
&& u->conf->cache_revalidate)
|
||||
{
|
||||
time_t now, valid, updating, error;
|
||||
ngx_int_t rc;
|
||||
time_t now, valid, updating, error;
|
||||
ngx_int_t rc;
|
||||
ngx_msec_t valid_ms;
|
||||
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
||||
"http upstream not modified");
|
||||
|
|
@ -2898,10 +2899,11 @@ ngx_http_upstream_test_next(ngx_http_request_t *r, ngx_http_upstream_t *u)
|
|||
}
|
||||
|
||||
if (valid == 0) {
|
||||
valid = ngx_http_file_cache_valid(u->conf->cache_valid,
|
||||
u->headers_in.status_n);
|
||||
if (valid) {
|
||||
valid = now + valid;
|
||||
valid_ms = ngx_http_file_cache_valid(u->conf->cache_valid,
|
||||
u->headers_in.status_n);
|
||||
if (valid_ms) {
|
||||
valid = now + valid_ms / 1000;
|
||||
r->cache->valid_msec = valid_ms % 1000;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2991,15 +2993,18 @@ ngx_http_upstream_intercept_errors(ngx_http_request_t *r,
|
|||
}
|
||||
|
||||
if (u->cacheable) {
|
||||
time_t valid;
|
||||
time_t valid;
|
||||
ngx_msec_t valid_ms;
|
||||
|
||||
valid = r->cache->valid_sec;
|
||||
|
||||
if (valid == 0) {
|
||||
valid = ngx_http_file_cache_valid(u->conf->cache_valid,
|
||||
status);
|
||||
if (valid) {
|
||||
r->cache->valid_sec = ngx_time() + valid;
|
||||
valid_ms = ngx_http_file_cache_valid(
|
||||
u->conf->cache_valid, status);
|
||||
if (valid_ms) {
|
||||
r->cache->valid_sec = ngx_time() + valid_ms / 1000;
|
||||
r->cache->valid_msec = valid_ms % 1000;
|
||||
valid = r->cache->valid_sec;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -3428,17 +3433,20 @@ ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u)
|
|||
}
|
||||
|
||||
if (u->cacheable) {
|
||||
time_t now, valid;
|
||||
time_t now, valid;
|
||||
ngx_msec_t valid_ms;
|
||||
|
||||
now = ngx_time();
|
||||
|
||||
valid = r->cache->valid_sec;
|
||||
|
||||
if (valid == 0) {
|
||||
valid = ngx_http_file_cache_valid(u->conf->cache_valid,
|
||||
u->headers_in.status_n);
|
||||
if (valid) {
|
||||
r->cache->valid_sec = now + valid;
|
||||
valid_ms = ngx_http_file_cache_valid(u->conf->cache_valid,
|
||||
u->headers_in.status_n);
|
||||
if (valid_ms) {
|
||||
r->cache->valid_sec = now + valid_ms / 1000;
|
||||
r->cache->valid_msec = valid_ms % 1000;
|
||||
valid = r->cache->valid_sec;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -4877,12 +4885,13 @@ ngx_http_upstream_finalize_request(ngx_http_request_t *r,
|
|||
if (u->cacheable) {
|
||||
|
||||
if (rc == NGX_HTTP_BAD_GATEWAY || rc == NGX_HTTP_GATEWAY_TIME_OUT) {
|
||||
time_t valid;
|
||||
ngx_msec_t valid_ms;
|
||||
|
||||
valid = ngx_http_file_cache_valid(u->conf->cache_valid, rc);
|
||||
valid_ms = ngx_http_file_cache_valid(u->conf->cache_valid, rc);
|
||||
|
||||
if (valid) {
|
||||
r->cache->valid_sec = ngx_time() + valid;
|
||||
if (valid_ms) {
|
||||
r->cache->valid_sec = ngx_time() + valid_ms / 1000;
|
||||
r->cache->valid_msec = valid_ms % 1000;
|
||||
r->cache->error = rc;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue