Clear Varnish and Drupal caches with a simple shell script | NetEngine

Clear Varnish and Drupal caches with a simple shell script

Tim Tuesday, 9 November 2010

We are regularly clearing both Drupal and Varnish caches on our development box, so we chained these two commands together to simplify the process to a single, easy to type command: ‘cac’ (clear all caches)


#!/bin/bash echo "purge req.url ~ .*" | socat - TCP4: &amp;&amp; echo "Purged Varnish Cache"`</pre>

### cac:
<pre>`#!/bin/bash drush cc all &amp;&amp; clearvarnishcache `</pre>

Install these two scripts at:

Add execute permissions to both commands and simply call

from within any Drupal installation and voila!, all Drupal caches and Varnish caches should have been cleared. Be aware **this will clear the varnish cache for all Drupal sites on this server;** your sites may experience a performance hit as the Varnish cache gets rebuilt.
<pre>`ยป cac 'all' cache was cleared [success] 200 154 ----------------------------- Varnish HTTP accelerator CLI. ----------------------------- Type 'help' for command list. Type 'quit' to close CLI session. 200 0 Purged Varnish Cache

Note: Clearing the Drupal cache from the command-line requires Drush; if you’re used to the shell and are not already using Drush to make your Drupal admin tasks easier: you should be.


Credit for Varnish cache clear to David Strauss

comments powered by Disqus