Welcome! Log In Create A New Profile

Advanced

Nginx Cache | @ prefix example

Posted by c0nw0nk 
c0nw0nk
Nginx Cache | @ prefix example
May 12, 2018 06:10AM
So it says this on the docs :
http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_valid

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...?

//unknown outcome / result...?
X-Accel-Expires: @0

//Expire cache straight away.
X-Accel-Expires: 0

//Expire cache in 5 seconds
X-Accel-Expires: 5

//Expire cache in 5 seconds and allow "STALE" cache responses to be stored
for 5 seconds ?????
X-Accel-expires: @5 5

Hopefully I am right thinking that the above would work like this need some
clarification.

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

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Francis Daly
Re: Nginx Cache | @ prefix example
May 17, 2018 12:50AM
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_valid
>
> 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@daoine.org
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
c0nw0nk
Re: Nginx Cache | @ prefix example
May 17, 2018 07:00AM
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@daoine.org
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx

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

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Francis Daly
Re: Nginx Cache | @ prefix example
May 17, 2018 09:20AM
On Thu, May 17, 2018 at 12:50:10AM -0400, c0nw0nk wrote:

Hi there,

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

You're welcome.

> 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.

A unix time stamp is "absolute time in seconds since Epoch".

That is: it is a single number, probably 10 digits long for anything
currently useful.

Right now, it is:

$ date +%s
1526540978

So if you want to set the expiry time of "in about an hour", you could
send a header of

X-Accel-Expires: @1526544000

where that timestamp corresponds to

$ date -u -d @1526544000
Thu May 17 08:00:00 UTC 2018

The X-Accel-Expires header should have a single value: either digits,
or an @ followed by digits.

f
--
Francis Daly francis@daoine.org
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Sorry, only registered users may post in this forum.

Click here to login