Purging Cache

Purging Cache

Purging Cache

PURGE is a specialized HTTP command. This command is comprehensible to proxy servers like Squid, Varnish and Enfold Proxy; it orders the proxy server to evict the item from cache so future requests will fetch a fresh new copy. On the machine with Enfold Proxy, files will essentially be deleted from C:\Program Files\Enfold Proxy\cache\host www.originalfunsite.com\data .

Important: Purging will not work if you have set the Aggressive caching profile in Enfold Server.

Purging is a useful action when trying to test various cache settings in Plone. Sometimes, if you make an incorrect cache setting in CacheFu or set an incorrect header on a Plone template, you can use the purge feature to wipe away previous content downloaded when the incorrect cache settings were in effect. Normally, it won't be necessary to run purge on a live site except as a "last resort mechanism" to correct a wrong cache setting.

Purging from a Remote Machine

Enfold Proxy (EP) has controls to prevent purging commands from being issued by anyone. Generally, before you can do any purging, you need to explicitly declare which I.P. addresses are allowed to issue a PURGE command.

To do this, open the EP configuration utility from the Start menu, go to Settings --> Caching purge sources and type the I.P. address of any computer which will issue a PURGE command. At minimum, you need to type the IP address corresponding to your Plone or Enfold Server. This is required if you are going to run a PURGE command from within a Plone product. If you intend using a local command-line tool (like cURL) along with a remote Plone server, you must include the I.P. addresses of both the localhost ( and the Plone host.

Note In many cases, it is necessary to type in 2 IP addresses here. First, (which is localhost) and second, the actual IP address of your machine (such as If you are testing when logged on as a domain user on the machine itself, sometimes IIS will treat domain requests as coming from outside the machine itself. If you are unsure which IP address is making the PURGE request, examine your IIS HTTP access logs and verify the IP address which made the PURGE request.

Special Note about Windows authentication (NTLM) and Purging. Enfold Server (ES) lets you use NTLM authentication to automatically log users in. If you are using NTLM with Enfold Server, you might not be able to run purge commands successfully. This is a known bug with Enfold Proxy 4.

In Enfold Proxy (EP), there are four ways to purge the cache.
  1. use the Purge button within Enfold Proxy. (recommended)
  2. use the portal_squid tool within the ZMI (helpful for purging one specific URL only).
  3. use a command line utility like cURL or Telnet to issue a PURGE command (which the proxy server can understand) for a specific URL.
  4. do it from within a Plone caching product (like CacheFu or CMFSquidTool).
  5. include a Python script to purge cache content when an item is republished.

This topic will discuss the advantages and disadvantages of each method.

Purge Cache within Enfold Proxy (Recommended)

Enfold Proxy includes a way to purge cache. To do this, select the Purge option on the left panel of EP's configuration utility. By checking or unchecking each proxy definition, you can delete the cache for one or multiple proxy definitions.


Purge a specific URL with Portal_Cache

Portal_cache is a product that comes installed by default on Enfold Server. It also comes with the CacheFu suite of products. This product (visible in the ZMI, but not Plone), lets you input a specific URL you wish to be cached. Keep in mind that this URL will only cache a specific item. So if you try to purge www.originalfunsite.com/news, it will not purge cache of jpegs or css files used on this web page. Instead this request will purge only the contents of that page (minus the css/jpg/gif/js files).

To do this:

  1. Confirm that the IP address of the requesting machine is explicitly listed in Enfold Proxy (Settings --> Cache Purging Source). If your IP address is not listed, enter it now.
  2. Go to the ZMI for your site and open the portal_squid tool. Located at /Plone/portal_squid (Plone Site Setup --> Zope Management Interface --> portal_squid (in right panel, near the bottom).
  3. Follow the instructions for adding a Cache URL. Press Save. (Example: http://www.originalfunsite.com).
  4. In the field for Purge URL Enter the name of the web item relative to the Plone root. (Example: logo.jpg). Logo.jpg is a company logo jpeg that is found on the Plone home page.
  5. Press Go.

Here are some responses you could conceivably receive after you press the Go button.

Using cURL for purging

cURL ( http://curl.haxx.se/docs/manual.html ) is a command line tool for making HTTP requests. With cURL you can make the purge request for a specific URL (rather than making a global command). Just use the command

curl -X PURGE http://host:port/path/to/url/to/be/purged

This tool is useful for testing and troubleshooting. However, if you are using a different machine, make sure that its IP address you are using to run cURL is listed as a "safe address" in the Caching Purge Sources field under Settings in EP's configuration utility.

The PURGEALL command allows you to remove all items in the cache, or all items that start with the specified string - or if you specify the root of the EP site, all items in the cache. For example

curl -X PURGEALL http://localhost/

would remove all cached items (assuming vh_root is set to point to the root of the IIS site.) Also note that specifying the -v option to cURL will show more information about the response to the purge request.

Using a Plone product to purge cache

If you install the CacheFu product, you can issue a global command to purge all the cache. See the CacheFu documentation for information about that. http://plone.org/products/cachefu In addition, the CMFSquidTool product (which comes on Enfold Server and documented above) includes the ability to do a global purge. When using a Plone product to issue a PURGE command, you need to include the I.P address of the Plone server with the Plone product.

Purging content when new content is republished

In the Chasseur product in Enfold Server, all cacheable items are cached for either 15 minutes or 60, depending on the policy you set. For images and css, there is little risk.

But what if you have a special URL (such as a home page or announcement page) where the content needs to stay as up to date as possible?

One solution (in CacheFu) is to create a new rule to handle a custom content type. (You will need to choose the Add New ContentCache Rule on the right dropdown box on the Rules tab). But an easier solution may simply be to include a simple python script to purge the cached item every time a Plone page has been republished.

The following steps illustrate how to create a simple Python script which will trigger a purge request.

  1. Using the Zope Management Interface (ZMI), click to your Plone site.

  2. Navigate to http://PloneServer:8080/Plone/portal_workflow/plone_workflow/manage_workspace (where Plone corresponds to your Plone site).

  3. Click on the Scripts tab. Using the Add dropdown tool on the right, add Script (Python).

  4. Name the ID on_publish. and select Add and Edit

  5. In the new web form, list "Purge content on Publication" in the title and the word "state" in the Parameter list.

  6. In the body of the script, add this:

    content = state['object']
    request = context.REQUEST
    squid = context.portal_squid
    url = content.absolute_url()
            squid.manage_pruneUrl(url, request)
            # Some versions of squidtool throw an error
            # that can not be caught in Python Scripts
  7. Press Save and ascend through the web interface to http://PloneServer:8080/Plone/portal_workflow/plone_workflow/transitions/submit/manage_workspace . You will see a dropdown box on the Script (After) field which lets you select the on_publish script you have just created and added.


Adding this will cause a Plone page cache to be purged whenever it is republished.