cache.config配置文件解读
生活随笔
收集整理的這篇文章主要介紹了
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=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文件中的注釋
總結
以上是生活随笔為你收集整理的cache.config配置文件解读的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 在ATS插件中使用互斥锁
- 下一篇: ATS和闰秒那些事儿