mod_expire

缓存控制与mod_expire
本文介绍如何使用mod_expire模块来控制HTTP响应头中的Expires和Cache-Control:max-age字段,实现对静态资源的有效缓存管理。重点讲解了配置语法、常见问题及解决方法,并探讨了与Etag配合使用的最佳实践。

Controlling the Expiration of Content in Caches¶
Module: mod_expire

Description:
mod_expire controls the Expire and Cache-Control: max-age headers in the Response Header of HTTP/1.0 and HTTP/1.1
messages. It is useful to set it for static files which should be cached
aggressively like images, stylesheets or similar.

Options:
expire.url
assigns a expiration to all files below the specified path. The
specification of the time is made up of:

<access|modification> <number> <years|months|days|hours|minutes|seconds>

where access means time of user access and modification means time of file modification. Follows the syntax used by mod_expire in Apache 1.3.x and later. (See: http://httpd.apache.org/docs/1.3/mod/mod_expires.html) Example:

    expire.url = ( "/images/" => "access 1 hours" )

Example to include all sub-directories:

    $HTTP["url"] =~ "^/images/" {
         expire.url = ( "" => "access 1 hours" )
    }

Troubleshoot:
It is known that mod_expire may not work due to an incorrect order of loading of modules. One instance is that mod_expire is loaded after mod_fastcgi. The solution is simple, it is to move mod_expire within the modules array in front of mod_fastcgi. Note: The order of the modules is loaded from top to bottom.

Symptoms of the above scenario is the server starts up fine but fails to serve content.

In 1.4.13 (and probably others) you must load mod_expire BEFORE mod_compress. Otherwise, expires headers will NOT be output when serving a compressed document.

Also, expire.url = ( "/images/" => "access 1 hours" ) did not work for me. I had to use the second form.

I tested in 1.4.18 and above two problem(one is order mod_expire and mod_compress and the other is expire time specification setting) is not appeared.

文章来源:http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ModExpire

我的测试:

过期时间(expire)是HTTP响应(response)的头部控制信息,浏览器会在指定过期时间内使用本地缓存,不用重新加载,对应的缓存对象主要是静态文件,如css,image, java; 可以在服务器端进行全局设置,也可以应用端进行设置,这里我会说下服务器端的设置


打开:"mod_expire",去掉前面的注释:"#"

#========================================================================================#
#------------------配置 expire 模块 设置过期时间----------------------------------------------#
#-----语法:<access|modification> <number> <years|months|days|hours|minutes|seconds>
#========================================================================================#
#data2及其子目录的规则:访问过期2小时

$HTTP["url"] =~ "^/data2/" {
#expire.url = ( "" => "modification 2 hours" ) #这个在浏览器访问会一次200(读取服务器文件) 一次304(读取本地缓存)轮流替换
expire.url  = ( "" => "access 6 hours" ) #这个第一次200 第二次304 以后就一直本地
}

有关Etag和Expires的文档,参见这里

所以mod_expire要配合Etag使用

etag 默认的配置 是根据系统的inode 可以选择为:modified-time
如果服务器有多台的话,就得配置:
etag.use-inode = "disable"
etag.use-mtime          = "enable" #使用修改时间,每台服务器的修改时间得一致,才能达到目的
我们现在配置的是:

#启用etag
static-file.etags =  "enable"
#使用文件修改时间
etag.use-mtime =  "enable"
#禁用系统inode
etag.use-inode = "disable"


另外官方解释:

Description
defines if the ETag generation algorithm will use the inode value of the file.
If you have multiple lighttpd servers serving static content then you should use

etag.use-inode = "disable"

So that the ETag value is consistent across the lighttpd clusters. Otherwise you will generate lesser number of 304 responses
Do make sure that the static content on all your clusters have the same mtime (modified-time)

Default: enabled

内容概要:本文系统介绍了算术优化算法(AOA)的基本原理、核心思想及Python实现方法,并通过图像分割的实际案例展示了其应用价值。AOA是一种基于种群的元启发式算法,其核心思想来源于四则运算,利用乘除运算进行全局勘探,加减运算进行局部开发,通过数学优化器加速函数(MOA)和数学优化概率(MOP)动态控制搜索过程,在全局探索与局部开发之间实现平衡。文章详细解析了算法的初始化、勘探与开发阶段的更新策略,并提供了完整的Python代码实现,结合Rastrigin函数进行测试验证。进一步地,以Flask框架搭建前后端分离系统,将AOA应用于图像分割任务,展示了其在实际工程中的可行性与高效性。最后,通过收敛速度、寻优精度等指标评估算法性能,并提出自适应参数调整、模型优化和并行计算等改进策略。; 适合人群:具备一定Python编程基础和优化算法基础知识的高校学生、科研人员及工程技术人员,尤其适合从事人工智能、图像处理、智能优化等领域的从业者;; 使用场景及目标:①理解元启发式算法的设计思想与实现机制;②掌握AOA在函数优化、图像分割等实际问题中的建模与求解方法;③学习如何将优化算法集成到Web系统中实现工程化应用;④为算法性能评估与改进提供实践参考; 阅读建议:建议读者结合代码逐行调试,深入理解算法流程中MOA与MOP的作用机制,尝试在不同测试函数上运行算法以观察性能差异,并可进一步扩展图像分割模块,引入更复杂的预处理或后处理技术以提升分割效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值