Welcome! Log In Create A New Profile

Advanced

[PATCH 1 of 2] Cache: don't update cache if revalidated response is not cacheable

Piotr Sikora
November 24, 2014 10:30PM
# HG changeset patch
# User Piotr Sikora <piotr@cloudflare.com>
# Date 1416886025 28800
# Mon Nov 24 19:27:05 2014 -0800
# Node ID 01f07fc7932b64f261c9e6cb778c87279fabcde2
# Parent 2c10db908b8c4a9c0532c58830275d5ad84ae686
Cache: don't update cache if revalidated response is not cacheable.

Signed-off-by: Piotr Sikora <piotr@cloudflare.com>

diff -r 2c10db908b8c -r 01f07fc7932b src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c Fri Nov 21 22:51:49 2014 +0300
+++ b/src/http/ngx_http_upstream.c Mon Nov 24 19:27:05 2014 -0800
@@ -2002,14 +2002,13 @@ ngx_http_upstream_test_next(ngx_http_req
&& u->cache_status == NGX_HTTP_CACHE_EXPIRED
&& u->conf->cache_revalidate)
{
- time_t now, valid;
+ time_t valid;
ngx_int_t rc;

ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"http upstream not modified");

- now = ngx_time();
- valid = r->cache->valid_sec;
+ valid = u->cacheable ? r->cache->valid_sec : 0;

rc = u->reinit_request(r);

@@ -2021,25 +2020,31 @@ ngx_http_upstream_test_next(ngx_http_req
u->cache_status = NGX_HTTP_CACHE_REVALIDATED;
rc = ngx_http_upstream_cache_send(r, u);

- if (valid == 0) {
- valid = r->cache->valid_sec;
- }
-
- if (valid == 0) {
- valid = ngx_http_file_cache_valid(u->conf->cache_valid,
- u->headers_in.status_n);
+ if (u->cacheable || valid) {
+ time_t now;
+
+ now = ngx_time();
+
+ if (valid == 0) {
+ 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) {
+ valid = now + valid;
+ }
+ }
+
if (valid) {
- valid = now + valid;
+ r->cache->valid_sec = valid;
+ r->cache->date = now;
+
+ ngx_http_file_cache_update_header(r);
}
}

- if (valid) {
- r->cache->valid_sec = valid;
- r->cache->date = now;
-
- ngx_http_file_cache_update_header(r);
- }
-
ngx_http_upstream_finalize_request(r, u, rc);
return NGX_OK;
}

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[PATCH 1 of 2] Cache: don't update cache if revalidated response is not cacheable

Piotr Sikora 680 November 24, 2014 10:30PM

[PATCH 2 of 2] Cache: test proxy_no_cache predicates before updating cache

Piotr Sikora 304 November 24, 2014 10:30PM

Re: [PATCH 2 of 2] Cache: test proxy_no_cache predicates before updating cache

Maxim Dounin 315 December 04, 2014 01:16PM

Re: [PATCH 2 of 2] Cache: test proxy_no_cache predicates before updating cache

Piotr Sikora 398 December 16, 2014 08:32PM

Re: [PATCH 1 of 2] Cache: don't update cache if revalidated response is not cacheable

Maxim Dounin 324 December 04, 2014 01:14PM

Re: [PATCH 1 of 2] Cache: don't update cache if revalidated response is not cacheable

Piotr Sikora 312 December 16, 2014 08:24PM

Re: [PATCH 1 of 2] Cache: don't update cache if revalidated response is not cacheable

Maxim Dounin 327 December 18, 2014 02:30PM

Re: [PATCH 1 of 2] Cache: don't update cache if revalidated response is not cacheable

Piotr Sikora 288 December 20, 2014 07:06PM

Re: [PATCH 1 of 2] Cache: don't update cache if revalidated response is not cacheable

Maxim Dounin 273 December 21, 2014 09:12PM

Re: [PATCH 1 of 2] Cache: don't update cache if revalidated response is not cacheable

Piotr Sikora 244 December 22, 2014 08:04PM

Re: [PATCH 1 of 2] Cache: don't update cache if revalidated response is not cacheable

Maxim Dounin 258 December 22, 2014 08:30PM

Re: [PATCH 1 of 2] Cache: don't update cache if revalidated response is not cacheable

Piotr Sikora 266 December 22, 2014 08:48PM

Re: [PATCH 1 of 2] Cache: don't update cache if revalidated response is not cacheable

Maxim Dounin 328 December 22, 2014 10:04PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 184
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready