question around ngx_http_get_flushed_variable()

Chris Newton cnewton at netflix.com
Mon Apr 4 19:44:38 UTC 2022


I'm a little unclear as to when ngx_http_get_flushed_variable() should be
used rather than ngx_http_get_indexed_variable(). The dev guide is a little
sparse, so I'm hoping someone could help.

The relevant flags within the ngx_variable_value_t with their dev guide
descriptions (followed by my interpretation) are:

unsigned    valid:1;

   - valid — The value is valid

The function used to generate the value has indeed been able to create a
valid value. When this is an indexed variable, it is then stored within the
ngx_http_request_t.variables array so that it can be reused for this
request without needing to be re-generated

unsigned    not_found:1;

   - not_found — The variable was not found and thus the data and len fields
   are irrelevant; this can happen, for example, with variables like
   $arg_foo when a corresponding argument was not passed in a request

This could not be generated, and re-attempting to do so won't succeed. As
such (for indexed variables), this is negatively cached within the same
ngx_http_request_t.variables array.

unsigned    no_cacheable:1;

   - no_cacheable — Do not cache result

The difference between functions is that the ngx_http_get_indexed_variable()
 returns a cached value and ngx_http_get_flushed_variable() flushes the
cache for non-cacheable variables.

That is, no_cacheable is only meaningful when
ngx_http_get_flushed_variable() is called rather than
ngx_http_get_indexed_variable(), when it causes the cached value to be
regenerated.



Are there any guidelines on when ngx_http_get_flushed_variable() should be
used instead of ngx_http_get_indexed_variable()?


It seems like it is 'practically never', but why for example does
ngx_http_get_variable() use

ngx_http_get_flushed_variable()?



TIA


Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20220404/28000e84/attachment.htm>


More information about the nginx-devel mailing list