Squid will hash the URL of the webpage requested by the user, generate a cache file, and store it in a directory. After squid is started, a hash table is created in the memory to record the cache file configuration on the hard disk.
For Web pages similar to http://jb51.net/index.html, squidwill only generate a slow storage file. You can use the squidclient tool included with squid to clear:
Squidclient-m PURGE-p 80 "http://jb51.net/index.html"
And for web pages with parameters, such as Sina podcast Flash Player http://vhead.blog.sina.com.cn/player/outer_player.swf? Auto = 0 & vid = 4469852 & uid = 1278987704, because "?" The following parameters are different, resulting in different URLs. squid will generate multiple cache files, and hash is scattered in different directories. If you modify this outer_player.swf file, it is very troublesome to delete many cached files in different directories and memory to update the squid cache. Therefore, I wrote a shell script for Linux, complete this troublesome task:
Script File Name: clear_squid_cache.sh
Download:Copy codeThe Code is as follows: clear_squid_cache.sh #! /Bin/sh
Squidcache_path = "/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
Note: grant clear_squid_cache.sh the executable permission (command: chmod + x./clear_squid_cache.sh ). Make sure that the script directory is writable.
Settings:
Squidcache_path = indicates the path of the squid cache directory
Squidclient_path = indicates the path of the squidclient program. The default value is bin/squidclient under the squid installation directory.
Usage:
1、clear all flash latencies (Extended name .swf ):
./Clear_squid_cache.sh swf
2. Clear all caches whose URLs contain sina.com.cn:
./Clear_squid_cache.sh jb51.net
3rd clear all cache files named zhangyan.jpg:
./Clear_squid_cache.sh test.jpg
Efficiency:
It was tested that it took about 2 minutes to clear 2950 cached files on DELL 26000. On average, 177 cached files can be cleared per second.