gpt4 book ai didi

Nginx 缓存不活动 vs proxy_cache_valid

转载 作者:行者123 更新时间:2023-12-04 11:26:42 28 4
gpt4 key购买 nike

Nginx 缓存配置:

proxy_cache_path /path/to/cache levels=1:2 keys_zone=my_cache:10m max_size=10g 
inactive=60m use_temp_path=off;

server {
# ...
location / {
proxy_cache my_cache;
proxy_cache_valid 5m;
proxy_pass http://my_upstream;
}
}
不活跃

inactive specifies how long an item can remain in the cache without being accessed. In this example, a file that has not been requested for 60 minutes is automatically deleted from the cache by the cache manager process, regardless of whether or not it has expired.


proxy_cache_valid

Sets caching time for different response codes.If only caching time is specified then only 200, 301, and 302 responses are cached.


是否 proxy_cache_valid覆盖无效? 5m 后缓存文件是否存在?

最佳答案

来自 this博文两句:

Turns out proxy_cache_valid instructs Nginx that the resource could be cached for 1y IF the resource doesn’t become inactive first. When you request a resource that has longer expiration but has become inactive due lack of requests, it causes a cache miss.


Conclusionproxy_cache_path should have a higher inactive time than the Expiration time of the requests (proxy_cache_valid).


来自 official Nginx guide :

inactive specifies how long an item can remain in the cache without being accessed. In this example, a file that has not been requested for 60 minutes is automatically deleted from the cache by the cache manager process, regardless of whether or not it has expired. The default value is 10 minutes (10m). Inactive content differs from expired content. NGINX does not automatically delete content that has expired as defined by a cache control header (Cache-Control:max-age=120 for example). Expired (stale) content is deleted only when it has not been accessed for the time specified by inactive. When expired content is accessed, NGINX refreshes it from the origin server and resets the inactive timer.


所以,你的问题的答案:

Does proxy_cache_valid override inactive? 5m later does the cached file exist or not?


不,他们是成对工作的。
  • proxy_cache_valid使缓存在 5 分钟内过期。
  • 如果缓存(不管是否过期)在 10 分钟内没有被访问 - Nginx 将其删除。
  • 如果在 10 分钟内访问了过期的缓存 - NGINX 从源服务器刷新它并重置不活动的计时器。

  • 还有 this answer可以帮助理解 proxy_cache_validinactive更好的。

    关于Nginx 缓存不活动 vs proxy_cache_valid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64151378/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com