您的位置:首页 > 其它

cache.config配置文件解读

2015-06-28 10:00 387 查看
这个是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对象,所有其它对象每小时验证一次

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文件中的注释
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: