diff src/http/ngx_http_file_cache.c @ 5736:2fe1967f8854

Cache: version in cache files. This allows to change the structure of cache files without spamming logs with false alerts.
author Maxim Dounin <mdounin@mdounin.ru>
date Thu, 26 Jun 2014 02:27:21 +0400
parents 25ade23cf281
children 44b9ab7752e3
line wrap: on
line diff
--- a/src/http/ngx_http_file_cache.c
+++ b/src/http/ngx_http_file_cache.c
@@ -498,6 +498,12 @@ ngx_http_file_cache_read(ngx_http_reques
 
     h = (ngx_http_file_cache_header_t *) c->buf->pos;
 
+    if (h->version != NGX_HTTP_CACHE_VERSION) {
+        ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
+                      "cache file \"%s\" version mismatch", c->file.name.data);
+        return NGX_DECLINED;
+    }
+
     if (h->crc32 != c->crc32) {
         ngx_log_error(NGX_LOG_CRIT, r->connection->log, 0,
                       "cache file \"%s\" has md5 collision", c->file.name.data);
@@ -875,6 +881,7 @@ ngx_http_file_cache_set_header(ngx_http_
 
     ngx_memzero(h, sizeof(ngx_http_file_cache_header_t));
 
+    h->version = NGX_HTTP_CACHE_VERSION;
     h->valid_sec = c->valid_sec;
     h->last_modified = c->last_modified;
     h->date = c->date;
@@ -1042,7 +1049,8 @@ ngx_http_file_cache_update_header(ngx_ht
         goto done;
     }
 
-    if (h.last_modified != c->last_modified
+    if (h.version != NGX_HTTP_CACHE_VERSION
+        || h.last_modified != c->last_modified
         || h.crc32 != c->crc32
         || h.header_start != c->header_start
         || h.body_start != c->body_start)
@@ -1060,6 +1068,7 @@ ngx_http_file_cache_update_header(ngx_ht
 
     ngx_memzero(&h, sizeof(ngx_http_file_cache_header_t));
 
+    h.version = NGX_HTTP_CACHE_VERSION;
     h.valid_sec = c->valid_sec;
     h.last_modified = c->last_modified;
     h.date = c->date;