Zend framework Cache

Caching have a phenomenal effect on server reducing load and better utilizing resources.

Zend framework provides Zend_Cache as a generic way to cache any data. You may cache sql queries, objects, variables, html contents etc.
Using Zend_Cache is fairly simple like

Saving a content into cache

$cache->save($content, "content_key");

getting saved/cached contents

$content = $cache->load("content_key");

here we configure zend framework application to work with cache

open your bootstrap file and add a function as below

public function _initCache()
	$frontendOptions = array (
		'lifetime' => 30,   //cache it for 30 seconds
		'automatic_serialization' => true
	$backendOptions = array (
                //assumes a a directory exists in following path
		'cache_dir' => APPLICATION_PATH . '/../data/cache/'
	$cache = Zend_Cache::factory('Page', 'File', $frontendOptions, $backendOptions);
	Zend_Registry::set('cache', $cache);

In your application you can use Zend_Cache as

$cache = Zend_Registry::get('cache');


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s