Nginx Cache Valid till - Help

Maxim Dounin mdounin at mdounin.ru
Sun Nov 14 19:34:57 MSK 2010


Hello!

On Sun, Nov 14, 2010 at 12:10:59AM -0500, rajivv wrote:

> I have a issue my nginx cofig is working ok just i want cache to clear
> only once in 15 days.
> But it is clearing everyday and new images showing on homepage ( we use
> random images hence on each refresh its new)
> however with nginx it needs to show same page and images etc picked from
> cache.
> It works ok for 24 hours then again refreshes all content...as if cache
> is clear.

I guess by "random images" you mean random <img src=""> in your
html code, right?

[...]

> http {
>     proxy_cache_path /var/lib/nginx/tmp/cache1 levels=1:2
> keys_zone=proxy_cache1:16m max_size=20g inactive=1d;
>     proxy_cache_path /var/lib/nginx/tmp/cache2 levels=1:2
> keys_zone=proxy_cache2:16m max_size=40g inactive=30d;
>     proxy_temp_path /var/lib/nginx/tmp/proxy;

[...]

>     location / {

[...]

>     proxy_cache_key
> "$server_name$scheme$proxy_host$uri$is_args$args$cookie_sid";
>     proxy_cache	proxy_cache1;

Note that your cache key for html contains $cookie_sid.  It looks 
like session cookie, and probably per-user and likely to expire 
somewhere earlier than after 15 days.

Also note that it uses proxy_cache1 which has 1d inactivity 
timeout, i.e. if no requests for a given key (with $cookie_sid)
seen by nginx within 1d cache entry will be removed.

Maxim Dounin



More information about the nginx mailing list