2bua-a
Last Updated: February 25, 2016
·
1.756K
· lordkeper

Clear varnish cache with capistrano

A simple example, how to flush varnish cache with capistrano 3.

namespace :varnish do
  set :varnish_auth, "/etc/varnish/secret"
  set :varnish_address, "127.0.0.1:6082"
  set :varnishadm, "/usr/bin/varnishadm"

  desc 'Flush entire cache'
  task :flush_all do
    on roles(:web) do
      execute "#{fetch(:varnishadm)} -T #{fetch(:varnish_address)} -S #{fetch(:varnish_auth)} ban \"req.url ~ ^/\""
    end
  end

  desc 'Flush assets cache'
  task :flush_assets do
    on roles(:web) do
      execute "#{fetch(:varnishadm)} -T #{fetch(:varnish_address)} -S #{fetch(:varnish_auth)} ban \"req.url ~ ^/assets/\""
    end
  end
end