博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
nginx缓存过期管理小结
阅读量:7035 次
发布时间:2019-06-28

本文共 1395 字,大约阅读时间需要 4 分钟。

缓存过期管理小结

先看一个经典的配置:

__path /cache levels=1:2 keys_zone=cache_pool:512minactive=1m max_size=10g;

location ~ .*\.(jpg|gif|png)$

{

    proxy_next_upstream   http_502 http_504 error timeout invalid_header;

    proxy_cache           cache_pool;

    proxy_cache_valid     200 304 2m;

    proxy_cache_key       $host$uri$is_args$args;

    proxy_set_header      Host $host;

    proxy_set_header      X-Forwarded-For  $remote_addr;

    proxy_pass            http://storage1;

    expires               10m;

}

我在论坛上看到有人问过,说这三个时间到底是什么意思,他们有什么用处?先看官网的解释:

Cached data that are not accessed during the time specified by the inactive parameter get removed from the cache regardless of their freshness. By default,inactive is set to 10 minutes.

(被的数据如果在inactive参数指定的时间内未被访问,就会被从缓存中移除,不论它是否是刚产生的。inactive的默认值是10分钟)

Sets caching time for different response codes. For example, the following directives

proxy_cache_valid 200 302 10m;

proxy_cache_valid 404      1m;

set 10 minutes of caching for responses with codes 200 and 302, and 1 minute for responses with code 404.

expires: Contro whether the response should be marked with an expiry time, and if so, what time that is.

这里总结下:

        inactive的时间表示一个文件在指定时间内没有被访问过,就从存储系统中移除,不管你proxy_cache_valid里设置的时间是多少。而proxy_cache_valid在保证inactive时间内被访问过的前提下,最长的可用时间。proxy_cache_valid定义的其实是一个绝对过期时间(第一次缓存的时间+配置的缓存时间),到了这个点,对象就被认为是过期,然后去后端重取数据,尽管它被访问的很频繁(即所谓的inactive时间内)。expires呢,它不在这个过期控制体系内,它用在发给客户端的响应中,添加"Expires"头。

  • 本文来自:

转载于:https://www.cnblogs.com/www886/p/4228386.html

你可能感兴趣的文章
关于CSS中 星号*的使用介绍
查看>>
好程序员Web前端教程分享Vue学习心得
查看>>
深入简出 好程序员教你HTML5开发基本常识
查看>>
HTTP和HTTPS详解。
查看>>
记录RBA(redo byte address)
查看>>
Oracle教程之管理UNDO(二)--监视UNDO表空间
查看>>
RAC在线替换OCR、DATA、FRA等ASM磁盘
查看>>
[Office]使用 Microsoft Office Live Workspace
查看>>
编译安装与RPM安装的区别
查看>>
我的友情链接
查看>>
linux下ftp的安全巧用之pureftp!
查看>>
初始化AppWidget框架结构
查看>>
[PHP] 文件系统交互
查看>>
我的友情链接
查看>>
文本处理“三剑客”之SED"
查看>>
find应用示例
查看>>
Kmail身份验证组件
查看>>
拷贝构造函数为何传入引用?
查看>>
at命令及服务
查看>>
resin app server安装总结
查看>>