Nginx Cache | @ prefix example

Francis Daly francis at daoine.org
Wed May 16 22:42:46 UTC 2018


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 at daoine.org


More information about the nginx mailing list