June 5, 2009

Caching in ZenMagick

Tags: , , , ,
Filed under: ZenMagick — DerManoMann @ 2:09 am

One of the perhaps less known services in ZenMagick is caching. ZenMagick knows two types of caches:

  • transient
    This type of cache exists for the duration of the request. Some services use this kind of caching, for example the product service. That allows the service to re-use already loaded products should they be requested again to increase performance.
  • persistent
    This type of cache will exist across multiple requests. As with all caching it might expire at some stage without warning.
    One good example of persistent cache usage is the page caching plugin.

For each type different implementations might exist, even though only one can be active at a time. The defaults for each type are:

transient -> memory

persistent -> file

To change the mapped implementation the setting cacheMapping can be used. For example, this line would change the persistent cache implementation to memcached:

ZMSettings::set('cacheMapping', array(MCache::PERSISTENT => 'memcache');

Currently, memory is the only transient cache type implemented, while there are a couple alternatives for persistent caching: memcache, xcache.

To add a new provider, you’ll have to implement the interface ZMCache and then register the new type following the example above. The name  of the cache and the class name (and also filename) follow this simple rule:

Name: foo

Class: FooCache

The class/filename ZMFooCache would actually also work, however convention is to leave the ZM prefix to core code/plugins.

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.