At the moment I'm not running Squid for this site but if experimentation time permits I'll have it running again soon. One thing I feel uneasy about is how to "manually" purge cached pages that needs to be updated. For example, if you read this page (and it's cached for one hour) and post a comment, then I'd like to re-cache this page with a purge. Setting a HTTP header could be something but that I would only be able to do on the page where you have this in the URL:
which, because of the presence of a querystring, is not necessarily cached anyway. The effect is that as soon as the "?msg=Comment+added" is removed from the URL, the viewer will see the page as it was before she posted her comment.
squidclient might be the solution. ...sort of.
squidclient is an executable program that you get when you install the squid cache server. As described in this documentation you can manually purge any cache on a site which would have the desired effect to the problem mentioned above. The only problem is that I have about 30-60 posted comments per day and that would be a hell of a lot of command line calls to squid. Secondly, they'd probably be quite slow and the person posting a comment won't be prepared to wait that long. The code for this would be something like this:
cmd = 'squidclient -m PURGE %s' % self.absolute_url() result = os.popen4(cmd).read() return result.find('200 OK') > -1
(obviously this would need to be wrapped in some security assertions)
An even better solution exists only as a dream. A Python binding for
squidclient that I can use directly from my Zope Python code:
# <pseudocode> import pysquidclient server = pysquidclient.Server('localhost', 80) r = server.purgeURL(self.absolute_url()) return r.isOK() # </pseudocode>
Imagine that! You could create the
server instance for the duration of the Zope server running just call the
purgeURL() function multiple times thus saving looooads of time. I guess it might be worth testing the
os.popen4() method to see if it works. If it doesn't work, then maybe it's time to start looking at ESI
Thanks Kevin (and Seb) for pointing this out. The solution is something like this:
(scheme, host, path, params, query, fragment ) = urlparse.urlparse(objecturl) h = httplib.HTTPConnection(host) h.request('PURGE', path) r = h.getresponse() return r.status, r.reason