Nginx cache returns MISS after a few hours, can't be set up to cache "forever"

classic Classic list List threaded Threaded
4 messages Options
mig
Reply | Threaded
Open this post in threaded view
|

Nginx cache returns MISS after a few hours, can't be set up to cache "forever"

mig
Hi,

I am trying to cache files "forever". Unfortunately in about 2-6 hours the cache starts to return MISS again. This is the setting:

---

proxy_cache_path /var/cache/nginx-cache  levels=1:2 keys_zone=mycache:10m max_size=20g inactive=10y;

proxy_cache_valid  10y;

"Expires" header returned by the upstream is set to the year 2027 and "Cache-Control" to max-age=315360000 (i.e. 10 years).

---

I suppose, if was the expiry time the reason, it would have return EXPIRED, but not MISS.

The cache fills up to ~5 GB (from allowed 20 GB), so the space should not be the problem.

I have tried to remove all cached files and restart nginx, but it did not help.

For testing I use plain curl GET requests (without ETag, Vary, etc. headers) - always the same.

Thank you for any hint,
Jan Molic
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Nginx cache returns MISS after a few hours, can't be set up to cache "forever"

Roman Arutyunyan
Hi,

On Tue, Nov 28, 2017 at 12:32:32PM +0100, [hidden email] wrote:

> Hi,
>
> I am trying to cache files "forever". Unfortunately in about 2-6 hours the cache starts to return MISS again. This is the setting:
>
> ---
>
> proxy_cache_path /var/cache/nginx-cache  levels=1:2 keys_zone=mycache:10m max_size=20g inactive=10y;
>
> proxy_cache_valid  10y;
>
> "Expires" header returned by the upstream is set to the year 2027 and "Cache-Control" to max-age=315360000 (i.e. 10 years).
>
> ---
>
> I suppose, if was the expiry time the reason, it would have return EXPIRED, but not MISS.
>
> The cache fills up to ~5 GB (from allowed 20 GB), so the space should not be the problem.
>
> I have tried to remove all cached files and restart nginx, but it did not help.
>
> For testing I use plain curl GET requests (without ETag, Vary, etc. headers) - always the same.

It's not only disk size that matters.
Cache entries may also be evicted when approaching the keyz_zone size.
Try increasing the zone size.

--
Roman Arutyunyan
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Nginx cache returns MISS after a few hours, can't be set up to cache "forever"

Peter Booth
In reply to this post by mig
Can you count the number of files that are in your cache and whether or not it's changing with time?
Then compare with the number of unique cache keys (from your web server log)

When the server starts returning a MISS - does it only do this for newer objects that haven’t been requested before?
Does it happen for any objects that had previously been returned as a HIT?



> On Nov 28, 2017, at 6:32 AM, [hidden email] wrote:
>
> Hi,
>
> I am trying to cache files "forever". Unfortunately in about 2-6 hours the cache starts to return MISS again. This is the setting:
>
> ---
>
> proxy_cache_path /var/cache/nginx-cache  levels=1:2 keys_zone=mycache:10m max_size=20g inactive=10y;
>
> proxy_cache_valid  10y;
>
> "Expires" header returned by the upstream is set to the year 2027 and "Cache-Control" to max-age=315360000 (i.e. 10 years).
>
> ---
>
> I suppose, if was the expiry time the reason, it would have return EXPIRED, but not MISS.
>
> The cache fills up to ~5 GB (from allowed 20 GB), so the space should not be the problem.
>
> I have tried to remove all cached files and restart nginx, but it did not help.
>
> For testing I use plain curl GET requests (without ETag, Vary, etc. headers) - always the same.
>
> Thank you for any hint,
> Jan Molic
> _______________________________________________
> nginx mailing list
> [hidden email]
> http://mailman.nginx.org/mailman/listinfo/nginx

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
mig
Reply | Threaded
Open this post in threaded view
|

Re: Nginx cache returns MISS after a few hours, can't be set up to cache "forever"

mig
In reply to this post by Roman Arutyunyan
Subject: Re: Nginx cache returns MISS after a few hours, can't be set up to cache "forever"

Hi,

thank you, yes, the problem was the keys_zone too low. There were ~80000 keys in the cache with only 10M zone size.

Jan

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx