comparison src/stream/ngx_stream_map_module.c @ 6832:ec10ce307dc0

Map: the "volatile" parameter. By default, "map" creates cacheable variables [1]. With this parameter it creates a non-cacheable variable. An original idea was to deduce the cacheability of the "map" variable by checking the cacheability of variables specified in source and resulting values, but it turned to be too hard. For example, a cacheable variable can be overridden with the "set" directive or with the SSI "set" command. Also, keeping "map" variables cacheable by default is good for performance reasons. This required adding a new parameter. [1] Before db699978a33f (1.11.0), the cacheability of the "map" variable could vary depending on the cacheability of variables specified in resulting values (ticket #1090). This is believed to be a bug rather than a feature.
author Ruslan Ermilov <ru@nginx.com>
date Thu, 08 Dec 2016 17:51:49 +0300
parents 014905eb7b3d
children
comparison
equal deleted inserted replaced
6831:014905eb7b3d 6832:ec10ce307dc0
24 ngx_array_t regexes; 24 ngx_array_t regexes;
25 #endif 25 #endif
26 26
27 ngx_stream_variable_value_t *default_value; 27 ngx_stream_variable_value_t *default_value;
28 ngx_conf_t *cf; 28 ngx_conf_t *cf;
29 ngx_uint_t hostnames; /* unsigned hostnames:1 */ 29 unsigned hostnames:1;
30 unsigned no_cacheable:1;
30 } ngx_stream_map_conf_ctx_t; 31 } ngx_stream_map_conf_ctx_t;
31 32
32 33
33 typedef struct { 34 typedef struct {
34 ngx_stream_map_t map; 35 ngx_stream_map_t map;
262 #endif 263 #endif
263 264
264 ctx.default_value = NULL; 265 ctx.default_value = NULL;
265 ctx.cf = &save; 266 ctx.cf = &save;
266 ctx.hostnames = 0; 267 ctx.hostnames = 0;
268 ctx.no_cacheable = 0;
267 269
268 save = *cf; 270 save = *cf;
269 cf->pool = pool; 271 cf->pool = pool;
270 cf->ctx = &ctx; 272 cf->ctx = &ctx;
271 cf->handler = ngx_stream_map; 273 cf->handler = ngx_stream_map;
276 *cf = save; 278 *cf = save;
277 279
278 if (rv != NGX_CONF_OK) { 280 if (rv != NGX_CONF_OK) {
279 ngx_destroy_pool(pool); 281 ngx_destroy_pool(pool);
280 return rv; 282 return rv;
283 }
284
285 if (ctx.no_cacheable) {
286 var->flags |= NGX_STREAM_VAR_NOCACHEABLE;
281 } 287 }
282 288
283 map->default_value = ctx.default_value ? ctx.default_value: 289 map->default_value = ctx.default_value ? ctx.default_value:
284 &ngx_stream_variable_null_value; 290 &ngx_stream_variable_null_value;
285 291
392 { 398 {
393 ctx->hostnames = 1; 399 ctx->hostnames = 1;
394 return NGX_CONF_OK; 400 return NGX_CONF_OK;
395 } 401 }
396 402
403 if (cf->args->nelts == 1
404 && ngx_strcmp(value[0].data, "volatile") == 0)
405 {
406 ctx->no_cacheable = 1;
407 return NGX_CONF_OK;
408 }
409
397 if (cf->args->nelts != 2) { 410 if (cf->args->nelts != 2) {
398 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 411 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
399 "invalid number of the map parameters"); 412 "invalid number of the map parameters");
400 return NGX_CONF_ERROR; 413 return NGX_CONF_ERROR;
401 } 414 }