Crash-Fu
A crash-course in CacheFu, squid, http acceleration, and a ton of useful links.
Basics
Start with these files, but also consider:
svn co https://svn.plone.org/svn/collective/CacheFu/trunk/CacheFu
I keep CacheFu in /opt/zope/src or $HOME/zope/src along with zope, python, and other related source files, and I run the scripts directly from there. In CacheFu/README.txt, Geoff Davis suggests simply putting some of these files in /etc/squid, a configuration which should generally work well, though much like the rest of the example config files, assumes that you have a single, system-installed squid.
I run everything out of $HOME/zope on one machine, and if you choose to do things this way, squid.conf is the least of your troubles, but will need a bit of attention. ;)
Installing Squid
There are a number of ways to install squid, and both the stable 2.x branch of squid and the unstable 3.0 branch are reported to work with CacheFu, the 3.0 branch having some interesting features. I've installed it on RedHat with RPMs, from FreeBSD ports, directly from source in my home directory, and possibly via Gentoo portage and/or fink on Mac OS X / Darwin.
I use daemontools to start squid and point explicitly to the squid binary and configuration file so that it doesn't matter how squid is installed, so long as it is linked and executes. You don't have to use daemontools, but if you do, this service script may be useful for you:
#!/bin/sh
exec 2>&1
exec setuidgid zope squid -f squid.conf -N -V -d1
You should provide full paths to the setuidgid and squid programs, as well as squid.conf, but I've truncated them for here. The -d1 flag is useful while testing your configuration, and should probably be removed later.
Grokking Squid
Apache Up-Front
If you want or need to configure squid behind apache somehow, you can use apache mod_rewrite to format requests for squid that contain pertinent information, like so:
RewriteEngine On
RewriteRule ^/(.*)$ http://127.0.0.1:3128/http/%{SERVER_NAME}:80/$1 [L,P]
This works within virtual hosts and is an effective way for routing virtual hosts through squid, although it is not necessary to put apache up front to virtual host with squid.
Base your squid.conf on CacheFu/squid_behind_apache/squid.conf and the corresponding redirector_class.py. If you read the comments, these will configure squid to expect RewriteRules like the one above, and may have other pertinent examples.
Direct Squid on port 80
Use CacheFu/squid_direct/squid.conf.
Tentacles
Make sure to make iRedirector.py and squidAcl.py scripts executable and adjust the locations of python in both shebang (#!) lines as well as changing default locations for logging and storage if it suits your purpose. Once you have basic functionality, consider configuring Zope and Squid with ICP.
We should also contact the maintainer of This page so that they might use iRedirector.py as an example redirector script. Because it's written in Python and uses mod_rewrite-like syntax, it is a very useful script in production and for example.
Helping Squid embrace Zope
Some useful zope addons are included in CacheFu and somewhat documented by geoffd in README.txt, such as:
- CMFSquid latches onto content objects to proactively purge cached views in squid.
- PageCacheManager uses etags and stuff somehow, I'm not 100% sure yet. ;)
- CacheSetup handles caching policies, and requires a CMF that is 1.5.5 or newer. Plone 2.1.2 or later should ship with this, get CMF 1.5.5+ separately if you use an older version in the 2.1 series.
Barnacles...
If you run into trouble, or want to do something more interesting, follow the yellow brick road to and through Squid integration pointers for more valuable references on http acceleration of Zope / Plone using Squid.
Happy Caching! ;)
