[nginx] Map: the "volatile" parameter.

洪志道 hongzhidao at gmail.com
Fri Dec 9 02:41:41 UTC 2016


Hi!

It's still a problem when the variable generated by map and including
itself. For example:

map $host $abc {
    default  $abc;
}

server {
    listen  80;

    location / {
        return 200 $abc;
    }
}

Thanks.
B.R~

2016-12-09 2:46 GMT+08:00 Ruslan Ermilov <ru at nginx.com>:

> details:   http://hg.nginx.org/nginx/rev/ec10ce307dc0
> branches:
> changeset: 6832:ec10ce307dc0
> user:      Ruslan Ermilov <ru at nginx.com>
> date:      Thu Dec 08 17:51:49 2016 +0300
> description:
> 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.
>
> diffstat:
>
>  src/http/modules/ngx_http_map_module.c |  15 ++++++++++++++-
>  src/stream/ngx_stream_map_module.c     |  15 ++++++++++++++-
>  2 files changed, 28 insertions(+), 2 deletions(-)
>
> diffs (92 lines):
>
> diff -r 014905eb7b3d -r ec10ce307dc0 src/http/modules/ngx_http_map_
> module.c
> --- a/src/http/modules/ngx_http_map_module.c    Thu Dec 08 17:29:01 2016
> +0300
> +++ b/src/http/modules/ngx_http_map_module.c    Thu Dec 08 17:51:49 2016
> +0300
> @@ -26,7 +26,8 @@ typedef struct {
>
>      ngx_http_variable_value_t  *default_value;
>      ngx_conf_t                 *cf;
> -    ngx_uint_t                  hostnames;      /* unsigned  hostnames:1
> */
> +    unsigned                    hostnames:1;
> +    unsigned                    no_cacheable:1;
>  } ngx_http_map_conf_ctx_t;
>
>
> @@ -265,6 +266,7 @@ ngx_http_map_block(ngx_conf_t *cf, ngx_c
>      ctx.default_value = NULL;
>      ctx.cf = &save;
>      ctx.hostnames = 0;
> +    ctx.no_cacheable = 0;
>
>      save = *cf;
>      cf->pool = pool;
> @@ -281,6 +283,10 @@ ngx_http_map_block(ngx_conf_t *cf, ngx_c
>          return rv;
>      }
>
> +    if (ctx.no_cacheable) {
> +        var->flags |= NGX_HTTP_VAR_NOCACHEABLE;
> +    }
> +
>      map->default_value = ctx.default_value ? ctx.default_value:
>
> &ngx_http_variable_null_value;
>
> @@ -395,6 +401,13 @@ ngx_http_map(ngx_conf_t *cf, ngx_command
>          return NGX_CONF_OK;
>      }
>
> +    if (cf->args->nelts == 1
> +        && ngx_strcmp(value[0].data, "volatile") == 0)
> +    {
> +        ctx->no_cacheable = 1;
> +        return NGX_CONF_OK;
> +    }
> +
>      if (cf->args->nelts != 2) {
>          ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
>                             "invalid number of the map parameters");
> diff -r 014905eb7b3d -r ec10ce307dc0 src/stream/ngx_stream_map_module.c
> --- a/src/stream/ngx_stream_map_module.c        Thu Dec 08 17:29:01 2016
> +0300
> +++ b/src/stream/ngx_stream_map_module.c        Thu Dec 08 17:51:49 2016
> +0300
> @@ -26,7 +26,8 @@ typedef struct {
>
>      ngx_stream_variable_value_t  *default_value;
>      ngx_conf_t                   *cf;
> -    ngx_uint_t                    hostnames;      /* unsigned
> hostnames:1 */
> +    unsigned                      hostnames:1;
> +    unsigned                      no_cacheable:1;
>  } ngx_stream_map_conf_ctx_t;
>
>
> @@ -264,6 +265,7 @@ ngx_stream_map_block(ngx_conf_t *cf, ngx
>      ctx.default_value = NULL;
>      ctx.cf = &save;
>      ctx.hostnames = 0;
> +    ctx.no_cacheable = 0;
>
>      save = *cf;
>      cf->pool = pool;
> @@ -280,6 +282,10 @@ ngx_stream_map_block(ngx_conf_t *cf, ngx
>          return rv;
>      }
>
> +    if (ctx.no_cacheable) {
> +        var->flags |= NGX_STREAM_VAR_NOCACHEABLE;
> +    }
> +
>      map->default_value = ctx.default_value ? ctx.default_value:
>                                               &ngx_stream_variable_null_
> value;
>
> @@ -394,6 +400,13 @@ ngx_stream_map(ngx_conf_t *cf, ngx_comma
>          return NGX_CONF_OK;
>      }
>
> +    if (cf->args->nelts == 1
> +        && ngx_strcmp(value[0].data, "volatile") == 0)
> +    {
> +        ctx->no_cacheable = 1;
> +        return NGX_CONF_OK;
> +    }
> +
>      if (cf->args->nelts != 2) {
>          ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
>                             "invalid number of the map parameters");
> _______________________________________________
> nginx-devel mailing list
> nginx-devel at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20161209/133f5335/attachment.html>


More information about the nginx-devel mailing list