Using Zend_Cache
Recently I needed to speed up the project that makes a lot of sevices call, like rss import, twitter, recapatcha etc. and some database calls. To solve this caching is the answer. Fortunately there is Zend_Cache that provides fast and easy function to do so.
First, you need a create directory which the cached files will be saved, i.e (tmp) and make rewritable (777), then the following of code lines will be place at the top of your bootstrap.php
// application/bootstrap.php
protected function _initCache()
{
$frontendOptions = array(
'lifetime' => 86400, // timestamp equivalent of 1 day
'debug_header' => false, // for debugging
'default_options' => array(
'cache_with_cookie_variables' => true,
'make_id_with_cookie_variables' => false
),
'regexps' => array(
// cache all controllers
'^/$' => array('cache' => true),
// cache the whole IndexController
'^/index/' => array('cache' => true),
)
);
$backendOptions = array(
'cache_dir' => 'tmp'
);
// getting a Zend_Cache_Frontend_Page object
$cache = Zend_Cache::factory('Page',
'File',
$frontendOptions,
$backendOptions);
$cache->start();
// if the cache is hit, the result is sent to the browser and the
// script stop here
// [...] the end of the bootstrap file
// these lines won't be executed if the cache is hit
}
This is only the basic caching that I can provide right now, will update sooner.
This post is tagged: zend, zend framework, zend framework tutorial
2 Responses to “Using Zend_Cache”
Leave a Reply

your place is valueble for me. thanks!
Your point of view is very useful and serious and you have delivered it with no concern. This takes both forward thinking and and I tip my hat off to you.