Nginx Cache | @ prefix example

c0nw0nk nginx-forum at forum.nginx.org
Thu May 17 04:50:10 UTC 2018


Thank you for the response and useful information Francis incredibly
helpful.

I am using the following function with this :
http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_background_update

proxy_cache_background_update on;




My webapp outputting the X-Accel-Expires header is PHP like so.

CODE:
<?php
echo(gmdate('D, d M Y H:i:s', 0) . ' GMT');
?>
OUTPUT:
Thu, 01 Jan 1970 00:00:00 GMT

The 0 would be replaced by the time function what is a UNIX time stamp.

CODE:
<?php
echo(gmdate('D, d M Y H:i:s', time()) . ' GMT');
?>
OUTPUT:
Thu, 17 May 2018 04:47:38 GMT

I have noticed the formate on this is different to what you provided here :
>>$ date -d @0

>>will say something corresponding to "Thu Jan 1 00:00:00 UTC 1970".

Should it look like yours or Nginx will read and understand it in the format
PHP is outputting it as ?


Francis Daly Wrote:
-------------------------------------------------------
> On Sat, May 12, 2018 at 12:05:51AM -0400, c0nw0nk wrote:
> 
> Hi there,
> 
> >
> http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_v
> alid
> > 
> > The “X-Accel-Expires” header field sets caching time of a response
> in
> > seconds. The zero value disables caching for a response. If the
> value starts
> > with the @ prefix, it sets an absolute time in seconds since Epoch,
> up to
> > which the response may be cached. 
> > 
> > Can someone give an example of how this should look and what if i
> set it as
> > zero what is the outcome then...?
> 
> The upstream sometimes wants to say "this is valid for an hour", and
> sometimes wants to say "this is valid until midnight". "For an hour"
> is "3600". "Until midnight" could be "work out the time difference
> between now and midnight, and set that number". Or it could be "when
> is
> midnight? Set @-that number".
> 
> The @-prefix is for when you want a thing to be cached until a
> specific
> time, rather that for a specific duration.
> 
> You can find the number to use by, for example, using
> 
> $ date -d 'tomorrow 0:0' +%s
> 
> and it will probably be 10 digits long.
> 
> > //unknown outcome / result...?
> > X-Accel-Expires: @0
> 
> $ date -d @0
> 
> will say something corresponding to "Thu Jan  1 00:00:00 UTC 1970".
> 
> So this asks to "cache until 1970". Which is in the past, so possibly
> is
> "expire cache now"; but if you really want to expire the cache now you
> should do just that.
> 
> > //Expire cache straight away.
> > X-Accel-Expires: 0
> 
> "disables caching" is what the documentation says.
> 
> > //Expire cache in 5 seconds
> > X-Accel-Expires: 5
> 
> "Cache for 5 seconds". That's probably the same thing.
> 
> > //Expire cache in 5 seconds and allow "STALE" cache responses to be
> stored
> > for 5 seconds ?????
> > X-Accel-expires: @5 5
> 
> The documentation you quoted doesn't seem to mention anything about
> STALE,
> or spaces in the header value. It looks like invalid input to nginx to
> me, so nginx could do anything (or nothing) with it.
> 
> > Hopefully I am right thinking that the above would work like this
> need some
> > clarification.
> 
> Request to cache for a duration -> use the number of seconds.
> 
> Request to cache until a time -> use @ and the time stamp in a
> particular
> format.
> 
> 	f
> -- 
> Francis Daly        francis at daoine.org
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,279762,279837#msg-279837



More information about the nginx mailing list