squid中的X-Cache和X-Cache-Lookup的意义

本文详细解析了CDN中X-Cache与X-Cache-Lookup的区别与含义,阐述了这两种缓存状态如何反映CDN节点上的缓存命中情况,并通过实例展示了不同配置下缓存行为的变化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在做的CDN的机器的http头中,我们常常见到X-Cache和X-Cache-Lookup的二个参数,那这二个参数分别是什么意思,有什么分别啦.

HTTP/1.0 200 OK
Expires: Mon, 23 Jun 2008 09:16:40 GMT
Cache-Control: max-age=60
Content-Type: text/html
Accept-Ranges: bytes
ETag: "985899363"
Last-Modified: Mon, 23 Jun 2008 08:17:40 GMT
Content-Length: 54218
Date: Mon, 23 Jun 2008 09:15:40 GMT
Server: Microsoft-IIS/7.0
Age: 20
X-Cache: HIT from cdcnc-253-238
X-Cache-Lookup: HIT from cdcnc-253-238:80
Via: 1.0 cdcnc-253-238 (squid/3.0.STABLE1-20080201)
Connection: close

见到了吗?很奇怪吧,HIT表示命中,怎么会有二个命中.
X-Cache:其实就个就是真实本机的HIT和MISS.

X-Cache-Lookup:这个就是向父,还有sibling模式的查询,比如ICP。之类命中的数据。

 

对于另一种情况:
HTTP/1.0 200 OK
Expires: Mon, 23 Jun 2008 09:16:40 GMT
Cache-Control: max-age=60
Content-Type: text/html
Accept-Ranges: bytes
ETag: "985899363"
Last-Modified: Mon, 23 Jun 2008 08:17:40 GMT
Content-Length: 54218
Date: Mon, 23 Jun 2008 09:15:40 GMT
Server: Microsoft-IIS/7.0
Age: 20
X-Cache: MISS from cdcnc-253-238
X-Cache-Lookup: HIT from cdcnc-253-238:80
Via: 1.0 cdcnc-253-238 (squid/3.0.STABLE1-20080201)
Connection: close

harvey兄给的解释:

1,文件在squid中超过了 refresh_p参数设置的时间,访问的时候会去后端验证,这个时候返回的是miss:
(X-Cache: MISS from cdcnc-253-238)
但发现后端文件并没有更新,所以squid继续使用cache文件,返回的就是hit:
X-Cache-Lookup: HIT from cdcnc-253-238:80

2,客户端给了一个ctrl+f5,但refresh_pattern参数中设置了reload-into-ms,这时文件也会到到后端验证,同样返回miss,但后端告诉squid文件未更新,所以squid继续从cache返回给client,返回的就是hit
(X-Cache-Lookup: HIT from cdcnc-253-238:80)

由于我的设置是:
refresh_pattern www.domian.com      10    0%      60        reload-into-ims
过期时间设置的很短,所以上述解释有可能是对的!
验证:
1.将参数换为ignore-reload,果然出现了两个HIT
2.改为refresh_pattern company.zhaopin.com      1440    0%      2880   reload-into-ims
时间加大,果然也出现两个HIT

{ "status_code": 403, "body": "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n<html><head>\n<meta type=\"copyright\" content=\"Copyright (C) 1996-2020 The Squid Software Foundation and contributors\">\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n<title>ERROR: The requested URL could not be retrieved</title>\n<style type=\"text/css\"><!--\n /*\n * Copyright (C) 1996-2023 The Squid Software Foundation and contributors\n *\n * Squid software is distributed under GPLv2+ license and includes\n * contributions from numerous individuals and organizations.\n * Please see the COPYING and CONTRIBUTORS files for details.\n */\n\n/*\n Stylesheet for Squid Error pages\n Adapted from design by Free CSS Templates\n http://www.freecsstemplates.org\n Released for free under a Creative Commons Attribution 2.5 License\n*/\n\n/* Page basics */\n* {\n\tfont-family: verdana, sans-serif;\n}\n\nhtml body {\n\tmargin: 0;\n\tpadding: 0;\n\tbackground: #efefef;\n\tfont-size: 12px;\n\tcolor: #1e1e1e;\n}\n\n/* Page displayed title area */\n#titles {\n\tmargin-left: 15px;\n\tpadding: 10px;\n\tpadding-left: 100px;\n\tbackground: url('/squid-internal-static/icons/SN.png') no-repeat left;\n}\n\n/* initial title */\n#titles h1 {\n\tcolor: #000000;\n}\n#titles h2 {\n\tcolor: #000000;\n}\n\n/* special event: FTP success page titles */\n#titles ftpsuccess {\n\tbackground-color:#00ff00;\n\twidth:100%;\n}\n\n/* Page displayed body content area */\n#content {\n\tpadding: 10px;\n\tbackground: #ffffff;\n}\n\n/* General text */\np {\n}\n\n/* error brief description */\n#error p {\n}\n\n/* some data which may have caused the problem */\n#data {\n}\n\n/* the error message received from the system or other software */\n#sysmsg {\n}\n\npre {\n}\n\n/* special event: FTP / Gopher directory listing */\n#dirmsg {\n font-family: courier, monospace;\n color: black;\n font-size: 10pt;\n}\n#dirlisting {\n margin-left: 2%;\n margin-right: 2%;\n}\n#dirlisting tr.entry td.icon,td.filename,td.size,td.date {\n border-bottom: groove;\n}\n#dirlisting td.size {\n width: 50px;\n text-align: right;\n padding-right: 5px;\n}\n\n/* horizontal lines */\nhr {\n\tmargin: 0;\n}\n\n/* page displayed footer area */\n#footer {\n\tfont-size: 9px;\n\tpadding-left: 10px;\n}\n\n\nbody\n:lang(fa) { direction: rtl; font-size: 100%; font-family: Tahoma, Roya, sans-serif; float: right; }\n:lang(he) { direction: rtl; }\n --></style>\n</head><body id=ERR_ACCESS_DENIED>\n<div id=\"titles\">\n<h1>ERROR</h1>\n<h2>The requested URL could not be retrieved</h2>\n</div>\n<hr>\n\n<div id=\"content\">\n<p>The following error was encountered while trying to retrieve the URL: <a href=\"http://172.25.128.1:13000/api/resume_analysis:create\">http://172.25.128.1:13000/api/resume_analysis:create</a></p>\n\n<blockquote id=\"error\">\n<p><b>Access Denied.</b></p>\n</blockquote>\n\n<p>Access control configuration prevents your request from being allowed at this time. Please contact your service provider if you feel this is incorrect.</p>\n\n<p>Your cache administrator is <a href=\"mailto:webmaster?subject=CacheErrorInfo%20-%20ERR_ACCESS_DENIED&body=CacheHost%3A%20squid-proxy-7877d5d865-z2vtt%0D%0AErrPage%3A%20ERR_ACCESS_DENIED%0D%0AErr%3A%20%5Bnone%5D%0D%0ATimeStamp%3A%20Thu,%2005%20Jun%202025%2016%3A15%3A17%20GMT%0D%0A%0D%0AClientIP%3A%2010.10.30.116%0D%0A%0D%0AHTTP%20Request%3A%0D%0APOST%20%2Fapi%2Fresume_analysis%3Acreate%20HTTP%2F1.1%0AAccept-Encoding%3A%20gzip,%20deflate,%20br,%20zstd%0D%0AConnection%3A%20keep-alive%0D%0AUser-Agent%3A%20python-httpx%2F0.27.2%0D%0AAccept%3A%20application%2Fjson%0D%0AContent-Type%3A%20application%2Fjson%0D%0AX-Locale%3A%20zh-CN%0D%0AX-Role%3A%20root%0D%0AX-Authenticator%3A%20basic%0D%0AAuthorization%3A%20Bearer%20eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEsInJvbGVOYW1lIjoicm9vdCIsImlhdCI6MTc0OTEzOTc3MywiZXhwIjoxNzUxNzMxNzczfQ.fwrzowTqH4tR6nT1QNP2AyT5cW4j_xjTwHvwR3yMzNE%0D%0AX-Timezone%3A%20+08%3A00%0D%0AX-Hostname%3A%20172.25.128.1%0D%0AX-App%3A%20main%0D%0AContent-Length%3A%2018%0D%0AHost%3A%20172.25.128.1%3A13000%0D%0A%0D%0A%0D%0A\">webmaster</a>.</p>\n<br>\n</div>\n\n<hr>\n<div id=\"footer\">\n<p>Generated Thu, 05 Jun 2025 16:15:17 GMT by squid-proxy-7877d5d865-z2vtt (squid)</p>\n<!-- ERR_ACCESS_DENIED -->\n</div>\n</body></html>\n", "headers": { "server": "squid", "mime-version": "1.0", "date": "Thu, 05 Jun 2025 16:15:17 GMT", "content-type": "text/html;charset=utf-8", "content-length": "4148", "x-squid-error": "ERR_ACCESS_DENIED 0", "vary": "Accept-Language", "content-language": "en", "x-cache": "MISS from squid-proxy-7877d5d865-z2vtt", "x-cache-lookup": "NONE from squid-proxy-7877d5d865-z2vtt:3128", "connection": "keep-alive" }, "files": [] }
06-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值