zoukankan      html  css  js  c++  java
  • nginx缓存过期管理小结

    nginx缓存过期管理小结

    先看一个经典的配置:

    proxy_cache_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: Controls 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"头。

  • 相关阅读:
    php socket 读取缓存区域
    PHP依赖注入的作用
    谷歌浏览器调试文字都变成font标签的解决方法
    php socket 同步异步堵塞非堵塞的区别
    css3中background-size中的cover与contain的区别
    css3 line-height:0的作用
    RDD的创建方式
    Serializable序列化操作解惑
    SparkCore分布式计算模拟
    spark不同环境下计算pi值
  • 原文地址:https://www.cnblogs.com/www886/p/4228386.html
Copyright © 2011-2022 走看看