[wp-hackers] GSoC Proposal: Caching in core

Brian Layman Brian at thecodecave.com
Wed Apr 2 18:13:42 GMT 2008


> I believe that's basically how the Zend framework handles caching.
> You give every cached object a unique identifier along with a bunch of
? tags.  That way you invalidate entries based on the ID or on any of
> the tags.
You are correct.  

To quote the Zend developer zone:
<blockquote>
In a real-world application you are likely to have several pieces of
information which are cached for every operation. You will want to be able
to manage these pieces of cached data as a group and not have to worry about
remembering all the ids of your saved data.

To handle this, Zend_Cache has implemented a tagging system. In Zend's
tagging system you can tag each cache entry with multiple tags, and unlike
the IDs, tags do not have to be unique. This means that you will have
multiple cache entries using the same tag, and are able to manage these as a
group. The tags are specified as an optional parameter to the save() method.

As an example:
<?php ... $userdata = array("theme" => "green"); $cache->save($time, 'time',
array('instance')); $cache->save($date, 'date', array('instance'));
$cache->save($userdata, 'user', array('user')); ...
$cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('instance'));
echo $cache->get('user'); ?> 

Here we are creating several entries into our cache system, but are using
tags to separate them into logical groups. We have a group for our date/time
information, and then a group that stores the specific user information. We
are going to use the clean() method to force the removal of the instance
data, but will retain the userdata for future use.

You will notice the use of a class constant in the above example. Zend
Framework has set a standard of using class constants (using the 'const'
construct) instead of global constants (using define()) whenever possible,
this keeps the global constant space clean.

Tags are only available in the file-based backend drivers.
</blockquote>

The string compares urk me, in all of these tag implementations.
______________________________________________
Brian Layman
b5media Inc.
www.b5Media.com / www.TheCodeCave.com / www.rhettandlink.com/live
Skype: BrianLayman
Twitter: http://www.twitter.com/brianlayman





More information about the wp-hackers mailing list