Add Zend Framework full page cache to your bootstrap
Posted on | January 24, 2012 | No Comments

Insert the function below into your bootstrap file.
// full page cache
protected function _initCache()
{
$dir = "location you would like to store cached pages";
$frontendOptions = array(
'lifetime' => 3600,
'content_type_memorization' => true,
'default_options' => array(
'cache' => true,
'cache_with_get_variables' => true,
'cache_with_post_variables' => true,
'cache_with_session_variables' => true,
'cache_with_cookie_variables' => true,
),
'regexps' => array(
// cache the whole IndexController
'^/.*' => array('cache' => true),
'^/index/' => array('cache' => true),
// place more controller links here to cache them
)
);
$backendOptions = array(
'cache_dir' =>$dir
);
// getting a Zend_Cache_Frontend_Page object
$cache = Zend_Cache::factory('Page',
'File',
$frontendOptions,
$backendOptions);
$cache->start();
}
Assign the directory that you would like to store the cache files to the -$dir- variable. Make sure the assigned directory can be read and written to. Also add some more controller regular expressions for the extra controllers you would like to also cache to the -regexps- array.
Once setup your pages will automatically be cached to a static cache file at your assigned location on your server for an hour. If you would like to cache the files for longer than an hour, increase the -lifetime- associative array value by increasing the seconds count.
Comments
Leave a Reply

