Welcome! Log In Create A New Profile

Advanced

[PATCH] Upstream: add $upstream_cache_age variable

Piotr Sikora
October 02, 2014 05:24PM
# HG changeset patch
# User Piotr Sikora <piotr@cloudflare.com>
# Date 1412284916 25200
# Thu Oct 02 14:21:56 2014 -0700
# Node ID 488aa8f86041dbe99a8f8ebbb3df533b9ce3e19e
# Parent a215d9021f137b9e2d4f69c37c7f992a2bef12c6
Upstream: add $upstream_cache_age variable.

This variable represents the amount of time that passed since the response
was fetched (or successfully revalidated) from the upstream server.

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

diff -r a215d9021f13 -r 488aa8f86041 src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c Tue Sep 30 17:20:33 2014 +0400
+++ b/src/http/ngx_http_upstream.c Thu Oct 02 14:21:56 2014 -0700
@@ -21,6 +21,8 @@ static ngx_int_t ngx_http_upstream_cache
ngx_http_variable_value_t *v, uintptr_t data);
static ngx_int_t ngx_http_upstream_cache_etag(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
+static ngx_int_t ngx_http_upstream_cache_age(ngx_http_request_t *r,
+ ngx_http_variable_value_t *v, uintptr_t data);
#endif

static void ngx_http_upstream_init_request(ngx_http_request_t *r);
@@ -373,6 +375,10 @@ static ngx_http_variable_t ngx_http_ups
ngx_http_upstream_cache_etag, 0,
NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_NOHASH, 0 },

+ { ngx_string("upstream_cache_age"), NULL,
+ ngx_http_upstream_cache_age, 0,
+ NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_NOHASH, 0 },
+
#endif

{ ngx_null_string, NULL, NULL, 0, 0, 0 }
@@ -4851,6 +4857,32 @@ ngx_http_upstream_cache_etag(ngx_http_re
return NGX_OK;
}

+
+static ngx_int_t
+ngx_http_upstream_cache_age(ngx_http_request_t *r,
+ ngx_http_variable_value_t *v, uintptr_t data)
+{
+ if (r->upstream == NULL
+ || r->upstream->cache_status <= NGX_HTTP_CACHE_EXPIRED
+ || r->upstream->cache_status == NGX_HTTP_CACHE_REVALIDATED)
+ {
+ v->not_found = 1;
+ return NGX_OK;
+ }
+
+ v->data = ngx_pnalloc(r->pool, NGX_TIME_T_LEN);
+ if (v->data == NULL) {
+ return NGX_ERROR;
+ }
+
+ v->len = ngx_sprintf(v->data, "%T", ngx_time() - r->cache->date) - v->data;
+ v->valid = 1;
+ v->no_cacheable = 0;
+ v->not_found = 0;
+
+ return NGX_OK;
+}
+
#endif



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

[PATCH] Upstream: add $upstream_cache_age variable

Piotr Sikora 787 October 02, 2014 05:24PM

Re: [PATCH] Upstream: add $upstream_cache_age variable

Roman Arutyunyan 376 October 03, 2014 09:30AM

[PATCH] Upstream: add $upstream_cache_age variable

Piotr Sikora 361 October 03, 2014 01:26PM

Re: [PATCH] Upstream: add $upstream_cache_age variable

Roman Arutyunyan 346 October 06, 2014 06:12AM

Re: [PATCH] Upstream: add $upstream_cache_age variable

Maxim Dounin 402 October 06, 2014 07:28AM

Re: [PATCH] Upstream: add $upstream_cache_age variable

Piotr Sikora 321 October 20, 2014 05:58AM



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

Online Users

Guests: 160
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready