Clears the script code sharing for the specified squid cache file.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.