question about proxy_cache_valid

Maxim Dounin mdounin at mdounin.ru
Thu Sep 10 21:55:40 MSD 2009


Hello!

On Thu, Sep 10, 2009 at 06:39:31PM +0200, s0cke at leech.it wrote:

> Hello,
>
> Maxim Dounin wrote:
>> Directive proxy_cache_valid specifies how long response will be  
>> considered valid (and will be returned without any requests to  
>> backend).  After this time response will be considered "stale" and  
>> either won't be returned or will be depending on proxy_cache_use_stale 
>> setting. 
>
> So when I use "proxy_cache_use_stale off;" which is default, nginx will  
> request the file again from the backend, if the time in  
> "proxy_cache_valid" is over?

Yes.

>> Argument "inactive" of proxy_cache_path specifies how long response 
>> will be stored in cache after last use.  Note that even stale responses 
>> will be considered recently used if there are requests to them.
>
> I am not quite sure whether I understand it correctly or not. I simply  
> want nginx to cache responses with 200 status for 2 hours. After this  
> time the response gets deleted from cache, so when new clients want the  
> file, nginx requests it again from backend.
> In other words: The requests should be stored in cache for 2 hours after  
> the last request from backend, not for 2 hours after the last request  
> from a client.
> Could you give me a hint on how to achieve this behavior?

No way.  Deleting files from cache is completely separate process, 
and it's based on last use time (LRU queue) and total cache size.  
This way nginx is able to manage cache efficiently.

>>> For some reason my cache still contains a file, that has been deleted 
>>> on  my backend 10 hours ago. Both, proxy_cache_valid and inactive= 
>>> are set  to 2h. Maybe the two settings have different meanings and I 
>>> do not  understand yet.
>>
>> Which version?  From the description it looks like a bug fixed in  
>> 0.8.14:
>>
>>     *) Bugfix: an expired cached response might stick in the "UPDATING" 
>>        state.
>>
>> If you see this in 0.8.14 - please provide more details.
>
> I am using the stable version (0.7.61). Do I have to update to 0.8.14 in  
> order to get this working? I'm not sure whether it's my config or a bug.

Stable doesn't have this fix yet, so you either have to upgrade or 
wait for fix to be merged.  No idea when merge will happen though.

> Hm.. and I can't figure out the meaning of the "updating" state. All the  
> other states are clear to me.

"UPDATING" means that response was considered stale and after it 
some request to backend was issued.  Such response may be returned 
to clients with "proxy_cache_use_stale updating;" without further 
actions as some request to backend that will update response in 
cache already in flight.

The bug is that nginx wasn't reset this state upon receiving 404 
from upstream, and hence cache manager wasn't able to remove this 
file even it was already inactive for a long time.

Maxim Dounin





More information about the nginx mailing list