Page-level cache for Zend Framework 1.x
The Framework_ActionHelpers_ControllerCache class is a sample of how to do page-level caching with Zend Framework. The basic approach is to look for the cached HTML in preDispatch. When it finds it, it calls $this->getRequest->setDispatched(false). That circumvents the entire action path and view rendering. For pages where we use it, we realized around 25-40% improved speed.
The advantage of this approach versus other Zend_Cache_Frontend patterns, such as Output, is that only the action script is cached, while other aspects of the layout, such as a global header, remain dynamic. Many sites show the user's name in the header, for example, and this approach easily handles that.
The other main component is Framework_ActionHelpers_CachedView. It wraps the Zend_View, and when called by ControllerCache, it also wraps view helpers with a Zend_Cache_Frontend_Class. After the view is rendered it combines all the snippets of HTML into one cache key for storage. In other words, CachedView is the real work-horse.
There are other supplementary classes hardly worth mentioning, along with simple unit tests, that exercise (admittedly) a fraction of the logic.
In its current form, these classes are reusable, but will probably require slight modification for your own needs. For example in ControllerCache, there is a static $requestParamsThatAffectContent array that requires hard-coded configuration. It may be worth tweaking such things so that it is more generally applicable and submitting a proposal to Zend, so that it is rolled into the framework. In that case a Zend Framework 2.0 migration may as well go along with it.
This code is released under the BSD license.