cache.config配置文件解读

这个是cdn配置缓存策略的文件,可以改变指定对象或是对象集的缓存参数cacheing paremeters
该文件默认存放在/usr/local/etc/trafficserver/,它定义了Traffic Server如何缓存web objects。
你能添加caching rules来指定如下东西:

  • 不缓存来自某个IP address的objects
  • 指定特定的objects在缓存中缓存多长时间(pin)
  • 多长时间后去验证cached objects是fresh的?
  • 是否忽略来自server端的no-cache指令

重要声明
在你修改完cache.config文件后, 请traffic_line -x来使修改生效(测试可行)。当你对Cluster中的某个node刷新
这些修改时,Traffic Server会自动将配置修改应用到集群内的其它所有节点。

配置文件格式解读
每行包含一个缓存规则,由若干键值对组成,键值对形如<tag>=<value>,Traffic Server识别3个空格分割的tag
primary_destination=value secondary_specifier=value action=value

每行必须包含一个主目标指示符primary destination specifiers,下列之一
dest_domain=  匹配来自某个url请求中的域名
dest_host=   匹配来自某个url请求中的主机名
dest_ip=    匹配来自某个url请求中的ip
url_regex=   匹配来自某个url请求的正则表达式
每行可以包含任意个数的不得重复的次指示符secondary specifiers(optional), 下列之一
port=       请求url中的port
scheme=     请求url中的protocol:http or https
prefix=     请求url中的path部分中的前缀prefix
suffix=     请求url中的file suffix后缀
method=     请求url的方法:GET,POST,PUT,TRACE等
time=       time range,比如08:00-14:00
src_ip=     client IP address的objects
internal    true或false,指定是否匹配源自内部API的http transaction
每行必须包含一个缓存指令cache directive,下列之一
action=nerver-cache             不缓存指定对象
action=ignore-no-cache          (client & server no cache)忽略所有的Cache-Control:no-cache头
action=ignore-client-no-cache   (only client no cache)忽略来自client request中的Cache-Control:no-cache头
action=ignore-server-no-cache   (only server no cache)忽略来自origin server response中的Cache-Control:no-cache头
cluster-cache-local  配置cluster cache去允许内容缓存到每个节点本地 
pin-in-cache=<time>  保留对象在缓存中的时间值,如1h15m20s,避免被改写,不影响不能缓存的对象,注意可能导致性能问题 
revalidate=<time>    配置重新验证时间 
ttl-in-cache=<time>   (force caching and expire after <time>),类似Cache-Control: max-age:<time> header
每行也可以包含各种不同的tweaks,以调整缓存参数,比如
cache-responses-to-cookies=<value>
对匹配的请求改写cookie全局设置proxy.config.http.cache.cache_responses_to_cookies

示例
dest_domain=www.example.com  scheme=http revalidate=2h
表示2小时后,重新验证来自www.example.com的所有http objects


dest_domain=data.video.qiyi.com  suffix=f4v action=never-cache

dest_domain=mydomain.com suffix=gif revalidate=6h
dest_domain=mydomain.com suffix=jpeg revalidate=6h
dest_domain=mydomain.com revalidate=1h

表示6小时后,重新验证mydomain.com中的gif和jpeg对象,所有其它对象每小时验证一次

dest_host=127.0.0.1  scheme=http ttl-in-cache=1d

考虑到ats内部的bug,这里应该用dest_host,而不是dest_ip,参见

https://blog.zymlinux.net/index.php/archives/293


url_regex=example.com/articles/popular.* time=19:00-23:00 ttl-in-cache=1d2h
使url正则在服务器内的 7-11 pm时间段内间断保留26小时
url_regex=example.com/game/.* pin-in-cache=1h
使符合该正则的url在缓存中保留1小时

参考文献
[1].https://docs.trafficserver.apache.org/en/latest/reference/configuration/cache.config.en.html

[2].cache.config文件中的注释

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值