diff options
| author | Roman Arutyunyan <arut@nginx.com> | 2016-12-22 14:25:34 +0300 |
|---|---|---|
| committer | Roman Arutyunyan <arut@nginx.com> | 2016-12-22 14:25:34 +0300 |
| commit | da2b2cf1e039630cec84e8b67d99c4d578361b0d (patch) | |
| tree | abe94ca9f27fa0322e0fda2ee4922e08e91bcdb9 /src/http/ngx_http_file_cache.c | |
| parent | 42f3dd2b843157ea0982b165b69c5dad84095811 (diff) | |
| download | nginx-da2b2cf1e039630cec84e8b67d99c4d578361b0d.tar.gz nginx-da2b2cf1e039630cec84e8b67d99c4d578361b0d.tar.bz2 | |
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.
Diffstat (limited to 'src/http/ngx_http_file_cache.c')
| -rw-r--r-- | src/http/ngx_http_file_cache.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/http/ngx_http_file_cache.c b/src/http/ngx_http_file_cache.c index a5a9300ac..731f6b09c 100644 --- a/src/http/ngx_http_file_cache.c +++ b/src/http/ngx_http_file_cache.c @@ -601,6 +601,8 @@ ngx_http_file_cache_read(ngx_http_request_t *r, ngx_http_cache_t *c) c->buf->last += n; c->valid_sec = h->valid_sec; + c->updating_sec = h->updating_sec; + c->error_sec = h->error_sec; c->last_modified = h->last_modified; c->date = h->date; c->valid_msec = h->valid_msec; @@ -632,6 +634,8 @@ ngx_http_file_cache_read(ngx_http_request_t *r, ngx_http_cache_t *c) now = ngx_time(); if (c->valid_sec < now) { + c->stale_updating = c->valid_sec + c->updating_sec >= now; + c->stale_error = c->valid_sec + c->error_sec >= now; ngx_shmtx_lock(&cache->shpool->mutex); @@ -1252,6 +1256,8 @@ ngx_http_file_cache_set_header(ngx_http_request_t *r, u_char *buf) h->version = NGX_HTTP_CACHE_VERSION; h->valid_sec = c->valid_sec; + h->updating_sec = c->updating_sec; + h->error_sec = c->error_sec; h->last_modified = c->last_modified; h->date = c->date; h->crc32 = c->crc32; @@ -1513,6 +1519,8 @@ ngx_http_file_cache_update_header(ngx_http_request_t *r) h.version = NGX_HTTP_CACHE_VERSION; h.valid_sec = c->valid_sec; + h.updating_sec = c->updating_sec; + h.error_sec = c->error_sec; h.last_modified = c->last_modified; h.date = c->date; h.crc32 = c->crc32; |
