comparison src/http/ngx_http_file_cache.c @ 6905:9a9e13686869

Cache: support for stale-while-revalidate and stale-if-error. Previously, there was no way to enable the proxy_cache_use_stale behavior by reading the backend response. Now, stale-while-revalidate and stale-if-error Cache-Control extensions (RFC 5861) are supported. They specify, how long a stale response can be used when a cache entry is being updated, or in case of an error.
author Roman Arutyunyan <arut@nginx.com>
date Thu, 22 Dec 2016 14:25:34 +0300
parents f18c285c2e59
children 1aeaae6e9446
comparison
equal deleted inserted replaced
6904:5e2423bce883 6905:9a9e13686869
599 } 599 }
600 600
601 c->buf->last += n; 601 c->buf->last += n;
602 602
603 c->valid_sec = h->valid_sec; 603 c->valid_sec = h->valid_sec;
604 c->updating_sec = h->updating_sec;
605 c->error_sec = h->error_sec;
604 c->last_modified = h->last_modified; 606 c->last_modified = h->last_modified;
605 c->date = h->date; 607 c->date = h->date;
606 c->valid_msec = h->valid_msec; 608 c->valid_msec = h->valid_msec;
607 c->body_start = h->body_start; 609 c->body_start = h->body_start;
608 c->etag.len = h->etag_len; 610 c->etag.len = h->etag_len;
630 } 632 }
631 633
632 now = ngx_time(); 634 now = ngx_time();
633 635
634 if (c->valid_sec < now) { 636 if (c->valid_sec < now) {
637 c->stale_updating = c->valid_sec + c->updating_sec >= now;
638 c->stale_error = c->valid_sec + c->error_sec >= now;
635 639
636 ngx_shmtx_lock(&cache->shpool->mutex); 640 ngx_shmtx_lock(&cache->shpool->mutex);
637 641
638 if (c->node->updating) { 642 if (c->node->updating) {
639 rc = NGX_HTTP_CACHE_UPDATING; 643 rc = NGX_HTTP_CACHE_UPDATING;
1250 1254
1251 ngx_memzero(h, sizeof(ngx_http_file_cache_header_t)); 1255 ngx_memzero(h, sizeof(ngx_http_file_cache_header_t));
1252 1256
1253 h->version = NGX_HTTP_CACHE_VERSION; 1257 h->version = NGX_HTTP_CACHE_VERSION;
1254 h->valid_sec = c->valid_sec; 1258 h->valid_sec = c->valid_sec;
1259 h->updating_sec = c->updating_sec;
1260 h->error_sec = c->error_sec;
1255 h->last_modified = c->last_modified; 1261 h->last_modified = c->last_modified;
1256 h->date = c->date; 1262 h->date = c->date;
1257 h->crc32 = c->crc32; 1263 h->crc32 = c->crc32;
1258 h->valid_msec = (u_short) c->valid_msec; 1264 h->valid_msec = (u_short) c->valid_msec;
1259 h->header_start = (u_short) c->header_start; 1265 h->header_start = (u_short) c->header_start;
1511 1517
1512 ngx_memzero(&h, sizeof(ngx_http_file_cache_header_t)); 1518 ngx_memzero(&h, sizeof(ngx_http_file_cache_header_t));
1513 1519
1514 h.version = NGX_HTTP_CACHE_VERSION; 1520 h.version = NGX_HTTP_CACHE_VERSION;
1515 h.valid_sec = c->valid_sec; 1521 h.valid_sec = c->valid_sec;
1522 h.updating_sec = c->updating_sec;
1523 h.error_sec = c->error_sec;
1516 h.last_modified = c->last_modified; 1524 h.last_modified = c->last_modified;
1517 h.date = c->date; 1525 h.date = c->date;
1518 h.crc32 = c->crc32; 1526 h.crc32 = c->crc32;
1519 h.valid_msec = (u_short) c->valid_msec; 1527 h.valid_msec = (u_short) c->valid_msec;
1520 h.header_start = (u_short) c->header_start; 1528 h.header_start = (u_short) c->header_start;