Skip to main content

Varnish cache: control cache using HTTP

We offer an HTTP API for the autonomous management of Varnish cache. This allows you to invalidate individual pages or entire areas or to update individual pages in the background.

To protect the API from misuse, access via ACL is restricted to certain IP addresses only.

The three basic operations are described below.

Purge

The purge command enables individual pages located in the cache to be invalidated. The next time this page is accessed, it will be loaded from the back-end and stored in the cache.

The following command invalidates the URL in the cache:

curl -X PURGE -D - http://www.nine.ch/site/to/purge.html

Ban

The ban command enables you to invalidate entire areas in the cache as opposed to individual pages only. Both the host name and the path can be defined via regular expression.

The following command invalidates all pages under /images/ at www.nine.ch:

curl -X BAN \
-H 'X-Ban-Host: www.nine.ch' \
-H 'X-Ban-Url: /images/.*' \
-D - http://127.0.0.1/

Refresh

The refresh command enables individual pages located in the cache to be updated in the background. All other clients will continue to be supplied with the old content until the update in the cache is complete.

The following command updates the URL in the cache:

curl -X REFRESH -D - http://www.nine.ch/site/to/purge.html