diff src/http/ngx_http_cache.h @ 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 1a917932db96
children 1aeaae6e9446
line wrap: on
line diff
--- a/src/http/ngx_http_cache.h
+++ b/src/http/ngx_http_cache.h
@@ -27,7 +27,7 @@
 #define NGX_HTTP_CACHE_ETAG_LEN      42
 #define NGX_HTTP_CACHE_VARY_LEN      42
 
-#define NGX_HTTP_CACHE_VERSION       3
+#define NGX_HTTP_CACHE_VERSION       4
 
 
 typedef struct {
@@ -71,6 +71,8 @@ struct ngx_http_cache_s {
 
     ngx_file_uniq_t                  uniq;
     time_t                           valid_sec;
+    time_t                           updating_sec;
+    time_t                           error_sec;
     time_t                           last_modified;
     time_t                           date;
 
@@ -114,12 +116,17 @@ struct ngx_http_cache_s {
     unsigned                         purged:1;
     unsigned                         reading:1;
     unsigned                         secondary:1;
+
+    unsigned                         stale_updating:1;
+    unsigned                         stale_error:1;
 };
 
 
 typedef struct {
     ngx_uint_t                       version;
     time_t                           valid_sec;
+    time_t                           updating_sec;
+    time_t                           error_sec;
     time_t                           last_modified;
     time_t                           date;
     uint32_t                         crc32;