hello world!
Published: September 29, 2010

Consolidating Cache Management in Zend Framework

In version 1.10, Zend added an Application Resource to the Zend Framework for easily setting up your Caching resources through configuration files.

The problem is that components like Doctrine, Zend_Translate, Zend_Db and so on all have directives for their own cache configurations.

This makes managing cache times, invalidations, and timeouts very difficult.

A solution to this is to use the cachemanger to create your cache then pass that cache onto your other components through the bootstrap ( see example below ).

Most of the Zend components are pretty straight forward in that they accept an instance of Zend_Cache. Doctrine on the other hand defines it's own cache drivers. Thanks to Benjamin Steininger we have a Doctrin_Cache driver implementation for Zend_Cache.

I made a small modification to the "save" method to add some custom cache tags, which I'll explain in a minute.

Zend_Cache tags allow for "categorizing" of cached items.

To make my tag management easier I created a class with all the tags I use as static properties. This also allows me to reflect on the class for building my cache admin interfaces.

Now, emptying specific groups of items from the cache is much easier since we can specify which tags I want to clean from the cache.

The set-up described gives me much better insite as to how my application is configured, allows for easier changes and managing my cache is much simpler.

Leave a Reply

linkedin-squaregithub-squarestack-overflowfacebook-official