[文章作者:张宴 本文版本:v1.0 最后修改:2007.08.02 转载请注明出处:http://blog.zyan.cc]

  Squid web缓存加速软件目前已经是新浪、搜狐、网易等各大网站广泛应用。Squid会在设置的缓存目录下建立多个目录,每一个目录下又建立多个目录,然后才在最里层的目录中存放缓存文件(object)。squid会根据用户请求网页的URL进行哈希,生成缓存文件,存放在某一个目录中。squid启动之后,将在内存中建立一个哈希表,记录硬盘中缓存文件配置的情形。

  对于类似http://you.video.sina.com.cn/index.html之类的网页,squid只会生成一个缓存文件。可以用squid附带的squidclient工具清除:
引用
squidclient -m PURGE -p 80 "http://you.video.sina.com.cn/index.html"


  而对于带有参数的网页,例如新浪播客的Flash播放器http://vhead.blog.sina.com.cn/player/outer_player.swf?auto=0&vid=4469852&uid=1278987704,因“?”后面的参数不同,导致URL也不同,squid会生成多个缓存文件,哈希分散存放在不同的目录。如果修改了这个outer_player.swf文件,要更新squid缓存就要去清除不同目录下及内存中的很多个缓存文件,十分麻烦,于是我编写了一个Linux下的shell脚本,去完成这件麻烦的事:

  脚本文件名:clear_squid_cache.sh(8月2日修正了UC网友“城市中的寂寞”反馈的BUG)
引用
#!/bin/sh
squidcache_path="/data1/squid/var/cache"
squidclient_path="/usr/local/squid/bin/squidclient"
grep -a -r $1 $squidcache_path/* | strings | grep "http:" | awk -F'http:' '{print "http:"$2;}' > cache_list.txt
for url in `cat cache_list.txt`; do
$squidclient_path -m PURGE -p 80 $url
done

  注意:请赋予clear_squid_cache.sh可执行权限(命令:chmod +x ./clear_squid_cache.sh)。请确保脚本所在目录可写。

  设置:
  squidcache_path= 表示squid缓存目录的路径
  squidclient_path= 表示squidclient程序所在的路径,默认为squid安装目录下的bin/squidclient

  用法:
  1、清除所有Flash缓存(扩展名.swf):
  ./clear_squid_cache.sh swf

  2、清除URL中包含sina.com.cn的所有缓存:
  ./clear_squid_cache.sh sina.com.cn

  3、清除文件名为zhangyan.jpg的所有缓存:
  ./clear_squid_cache.sh zhangyan.jpg

  效率:
  经测试,在DELL 2950上清除26000个缓存文件用时2分钟左右。平均每秒可清除缓存文件177个。

Tags: , ,



技术大类 » Cache与存储 | 评论(36) | 引用(0) | 阅读(60315)
xujie555
2012-5-21 13:25
coach factory outlet uses graceful accessories to match the classical logo of coach, which is the best combination of coach. The handmade coach products?can make you more charming and graceful.coach factory online provides people many coach goods. If you wish to snatch the coach handbag, then this best method is made for that you like for coach discount.coach factory outlet online is a fashion brand to ensure its quality. With designer coach shoulder bags, you will always attract people's attention. The bags will emphasize your personal style and taste.<br/>
xujie333
2012-5-21 14:47
coach outlet online Store guarantee that all the coach handbags offered are own high quality. In addition , all of them are sold at an unexpected low price.If you want to purchase, just visit their website.coach factory outlet is really sizzling kinds of shopping way for you. With the usage of the replica designer coach bags, you can surely be able to change your individual looks in a stunning manner.Coach bags on sale from the coach outlet are cheap or discount prices that you certainly will stand out from the crowd on your next camping trip!<br/>
coach88888888 Email
2012-8-13 17:33
If you desire to go to Coach Factory Outlet, but have no idea in which to go, you can research online. It is no doubt that there is drastically information and details about it for the reference.Coach Factory Online are loved by many people, when you walk in the street, you could see many people take coach styles.hat experts claim Coach Outlet Online shopping is in the changes they are available in.Coach Outlet will send you a coupon in the post to use in their upon only after you type a achieve. The Coach bags are customarily somewhat many than the ones in the stores.
TEST
2013-5-1 14:55
$squidclient_path -m PURGE -p 80 $url需要改成 $squidclient_path -m PURGE -p 80 -h 127.0.0.1 $url不然有时候报错:assert "false" at line 684Ip::Address invalid? with IsIPv4()=F, IsIPv6()=TADDRESS: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1squidclient: Address.cc:684: void Ip::Address::GetAddrInfo(addrinfo*&, int) const: Assertion `false' failed.Aborted[root@sy-newweb-file-1 squid]# /ytxt/squid/bin/squidclient -h localhost -p 3128 -m Purge http://192.168.11.153:3128/.DS_Storeassert "false" at line 684Ip::Address invalid? with IsIPv4()=F, IsIPv6()=TADDRESS: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1squidclient: Address.cc:684: void Ip::Address::GetAddrInfo(addrinfo*&, int) const: Assertion `false' failed.Aborted好像指定为IPV6地址了
shz Email
2022-7-20 18:31
Easily, the article is actually the best topic on this registry related issue. I fit in with your conclusions and will eagerly look forward to your next updates.  Scam Risk
shz Email
2022-7-20 18:34
I have bookmarked your website because this site contains valuable information in it. I am really happy with articles quality and presentation. Thanks a lot for keeping great stuff. I am very much thankful for this site.  Scam Risk
shz Email
2022-7-20 18:38
First You got a great blog .I will be interested in more similar topics. i see you got really very useful topics, i will be always checking your blog thanks.  Scam Risk
shz Email
2022-7-20 18:44
Hi to everybody, here everyone is sharing such knowledge, so it’s fastidious to see this site, and I used to visit this blog daily  Scam Risk
shz Email
2022-7-20 19:00
I’ve been searching for some decent stuff on the subject and haven't had any luck up until this point, You just got a new biggest fan!..  Scam Risk
shz Email
2022-7-20 19:19
I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well..  Scam Risk
shz Email
2022-7-20 19:24
Well, this got me thinking what other workouts are good for those of us who find ourselves on the road or have limited equipment options.  Scam Risk
shz Email
2022-7-20 19:35
I have checked this link this is really important for the people to get benefit from.  Scam Risk
shzz Email
2022-7-20 19:37
This is just the information I am finding everywhere. Thanks for your blog, I just subscribe your blog. This is a nice blog..  Scam Risk
shz Email
2022-7-20 19:39
Very nice article, I enjoyed reading your post, very nice share, I want to twit this to my followers. Thanks!.  Scam Risk
Lucky cola
2024-2-7 15:12
Gaming nirvana starts here.  Lucky cola
分页: 2/2 第一页 上页 1 2 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]