If your site is correctly configured and you have set up expiry headers, you should not need to manually purge URLs from Varnish HTTP Cache. But occasionally – especially if you are developing a new, cacheable component – you may need to use a purge script.
When you publish a page using Contensis, the process is slightly different. If, for example there was an error on your underlying page, the old content would continue to get served even if it was throwing a 500 server error.
This behaviour is intended – if your page were to start showing errors on all servers, we still want to serve the stale content, until the issue is resolved.
Warning: Purging is final. When you purge a URL in this way, it will be immediately and permanently deleted from the cache.
DDOS or DOS Warning
With Varnish running in front of your websites, the webservers have a level of protection from overrun because most content is cached. So, multiple requests to the same page will not hit the webservers.
If you put this script in a publically accessible place, it is possible that someone who found it could purge and then call your page over and over – effectively getting around the site caching. We advise some form of security to protect access (eg. a key or password).
Implement the scripts
In order to implement the scripts, you will need the IP addresses of your Varnish server. This script is currently configured for a single server, but you could implement it for multiple servers.
To get the IP address for your Varnish server(s) you can visit the Contensis Cloud dashboard and look up the servers named z-your-alias-CACHE.
Also bear in mind that Contensis Cloud webserver does not have any concept of your actual website URLs. Instead, they understand something along the lines of live-your-alias.cloud.contensis.com, as such any purge requests need to be made to the Contensis Cloud URL – not your domain.
You will need to use these two scripts:
Cache purge form: https://gitlab.zengenti.com/snippets/2
Purge Varnish: https://gitlab.zengenti.com/snippets/3
Note: Thanks go to the team at EUI and Brighton for helping with this article. EUI originally created the scripts, and Gareth from Brighton updated them to work with the new Contensis Cloud platform.