Difference between revisions of "Script to Clear a Page from Varnish Cache"

From Brian Nelson Ramblings
Jump to: navigation, search
(Script to Clear a Page from Varnish Cache)
(How to use the script)
Line 34: Line 34:
  
 
You should just need to change the domain name
 
You should just need to change the domain name
 +
 +
===Additional Articles===
 +
* [[Setup Varnish Cache]]
 +
* [[Setup Varnish for Magento]]
 +
* [[Setup Varnish for Wordpress]]
 +
* [[Setup Varnish for MediaWiki]]
 +
* [[Setup Varnish - Multiple Domains]]
 +
* [[Setup Varnish - Multiple Ipaddress]]

Revision as of 06:33, 19 January 2014

Script to Clear a Page from Varnish Cache

The script below will purge/ban a page from the varnish cache and then re-cache the page by curling it

#!/bin/bash

cmd="varnishadm -T 127.0.0.1:6082 -S /etc/varnish/secret"
site="http://www.briansnelson.com
page="$1"
 
if [ "$page" != "" ]; then
  echo -e "\nPurging old version from cache:"
  echo "-------------------------------"
  $cmd ban.url "^$page\$" | sed '/^$/d'
  $cmd ban.list | head -n 2
  echo -e "\nPopulating cache with new page content:"
  echo "---------------------------------------"
  curl -sL -w "%{http_code} %{url_effective}\n" $site/$page -o /dev/null
else
  echo Error: please provide a URL to purge..
fi

Once you have it download/setup on your system you will want to give the execute permission

chmod +x recache-varnish.script

How to use the script

bash recache-varnish.script <page to be purged/ban>
bash recache-varnish.script Main_Page

Or you can download the script here

You should just need to change the domain name

Additional Articles