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 .

Purging is a useful action when trying to test various cache settings in Plone. Sometimes, if you make an incorrect cache setting in plone.app.caching 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 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 (127.0.0.1) and the Plone host.

Note In many cases, it is necessary to type in 2 IP addresses here. First, 127.0.0.1 (which is localhost) and second, the actual IP address of your machine (such as 192.168.1.1). 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 add-on.
  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.

images/purgingsuccess.png

Purge a specific URL with Portal_Cache

Plone.app.caching or CacheFu 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 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 Add-On to purge cache

If you install plone.app.caching or CacheFu, you can issue a global command to purge all the cache. See the plone.app.caching documentation for information about that.