5

If I've config

fastcgi_cache_path /opt/nginx levels=1:2 keys_zone=TEST:100m inactive=40m;
..
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
fastcgi_cache_valid 30m;

How long will my cache stored in the path above?

6

fastcgi_cache_valid is used to define caching time for replies without "X-Accel-Expires", “Expires” or “Cache-Control” headers.
fastcgi_cache_path ... inactive= is used to define how long objects should be keeped in cache without accessing from browser.

So in your case with fastcgi_cache_valid 30m and fastcgi_cache_path ... inactive=40m all replies from original server without any Cache-control headers will be valid for 30 minutes (but could be used after 30 minutes in case of problems with original server if fastcgi_cache_use_stale is configured).
But cached object will be removed from cache if there will be no request for that object from users for 40 minutes.

| improve this answer | |
  • Thanks. I've updated my question that actually I also added "fastcgi_ignore_headers..", so my understanding is, at 31 minute, even thought the object is still in the cache and is active, my origin server will be contacted again for the request since it is no longer valid, right? So fastcgi_cache_valid should be always greater than inactive, right? – Ryan Nov 17 '16 at 17:42
  • You are right that origin server will be contacted at 31 minute. – Fedor Dikarev Nov 17 '16 at 19:07
  • 1
    As for fastcgi_cache_valid should be always greater than inactive -- they are totally independent values. cache_valid is used to determine how long this object is actual. While inactive is used to find non-popular objects and remove them from cache to reduce space usage. – Fedor Dikarev Nov 17 '16 at 19:16
  • Thanks for your reply. I understand they are independent but what I mean there is no point to set inactive greater than fastcgi_cache_valid since the cache is no longer valid, there is no need to store them in cache. – Ryan Nov 18 '16 at 3:55
  • You are right and in your case you can use lower inactive value. But you should consider that if you ever plan to use fastcgi_cache_use_stale functionality. – Fedor Dikarev Nov 18 '16 at 11:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.