9
9
10
10
static ngx_int_t ngx_http_srcache_expire_variable (ngx_http_request_t * r ,
11
11
ngx_http_variable_value_t * v , uintptr_t data );
12
+ static ngx_int_t ngx_http_srcache_fetch_status_variable (ngx_http_request_t * r ,
13
+ ngx_http_variable_value_t * v , uintptr_t data );
14
+
15
+
16
+ static ngx_str_t ngx_http_srcache_fetch_status [] = {
17
+ ngx_string ("BYPASS" ),
18
+ ngx_string ("MISS" ),
19
+ ngx_string ("HIT" )
20
+ };
12
21
13
22
14
23
static ngx_http_variable_t ngx_http_srcache_variables [] = {
@@ -17,6 +26,10 @@ static ngx_http_variable_t ngx_http_srcache_variables[] = {
17
26
ngx_http_srcache_expire_variable , 0 ,
18
27
NGX_HTTP_VAR_NOCACHEABLE , 0 },
19
28
29
+ { ngx_string ("srcache_fetch_status" ), NULL ,
30
+ ngx_http_srcache_fetch_status_variable , 0 ,
31
+ NGX_HTTP_VAR_NOCACHEABLE , 0 },
32
+
20
33
{ ngx_null_string , NULL , NULL , 0 , 0 , 0 }
21
34
};
22
35
@@ -67,6 +80,39 @@ ngx_http_srcache_expire_variable(ngx_http_request_t *r,
67
80
}
68
81
69
82
83
+ static ngx_int_t
84
+ ngx_http_srcache_fetch_status_variable (ngx_http_request_t * r ,
85
+ ngx_http_variable_value_t * v , uintptr_t data )
86
+ {
87
+ ngx_uint_t status ;
88
+ ngx_http_srcache_ctx_t * ctx ;
89
+
90
+ ctx = ngx_http_get_module_ctx (r , ngx_http_srcache_filter_module );
91
+
92
+ if (ctx == NULL ) {
93
+ status = NGX_HTTP_SRCACHE_FETCH_BYPASS ;
94
+
95
+ } else if (ctx -> from_cache ) {
96
+ status = NGX_HTTP_SRCACHE_FETCH_HIT ;
97
+
98
+ } else if (ctx -> issued_fetch_subrequest ) {
99
+ status = NGX_HTTP_SRCACHE_FETCH_MISS ;
100
+
101
+ } else {
102
+ status = NGX_HTTP_SRCACHE_FETCH_BYPASS ;
103
+ }
104
+
105
+ v -> valid = 1 ;
106
+ v -> no_cacheable = 1 ;
107
+ v -> not_found = 0 ;
108
+
109
+ v -> len = ngx_http_srcache_fetch_status [status ].len ;
110
+ v -> data = ngx_http_srcache_fetch_status [status ].data ;
111
+
112
+ return NGX_OK ;
113
+ }
114
+
115
+
70
116
ngx_int_t
71
117
ngx_http_srcache_add_variables (ngx_conf_t * cf )
72
118
{
0 commit comments