Clears the script code share for the specified squid cache file

  • 2020-05-06 12:00:51
  • OfStack

squid hashes the URL of the page requested by the user to generate a cache file that is stored in a directory. After squid starts, a hash table is created in memory to record the configuration of the cache files on the hard disk.

For similar http: / / jb51 net/index html web pages, such as squid will only generate a cache files. You can clear
with the squidclient tool that comes with squid
squidclient - m PURGE - p 80 "http: / / jb51. net/index. html"

For web pages with parameters, such as sina sows a guest Flash player http: / / vhead blog. sina. com. cn/player/outer_player swf? auto = 0 & vid = 4469852 & uid = 1278987704, because of "?" The following parameters are different, resulting in different URL, squid will generate multiple cache files, hash in different directories. If I changed the outer_player.swf file, it would be very troublesome to update the squid cache by clearing many cache files in different directories and in memory, so I wrote an shell script under Linux to do this troublesome thing:

Script file name: clear_squid_cache.sh

Download:
 
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: please grant clear_squid_cache.sh executable rights (command :chmod + x. / clear_squid_cache.sh). Make sure the script is writable in the directory.

Settings:
squidcache_path= represents the
path to the squid cache directory squidclient_path= indicates the path where the squidclient program is located. The default is bin/squidclient
in the squid installation directory
usage :
1. Clear all Flash caches (extension.swf) :

. / clear_squid_cache. sh swf
2. Clear all caches containing sina.com.cn in URL:

... / clear_squid_cache sh jb51 net
3. Clear all caches of file name zhangyan.jpg:

... / clear_squid_cache sh test jpg
Efficiency:
In tests, clearing 26,000 cache files on DELL 2950 took about two minutes. On average, 177 cache files are cleared per second.

Related articles: