File include cache in Zend Framework
Another box of tissue gone … runny nose syndrome continues … still cannot type or think …
Let me now blog something simple, but handy.
Problem … Zend Framework uses many types of plugins, how do we efficiently tell the application where to find the plugin files? For example, when we use a view helper, should our application find it in the Zend library directory? Should our application find it in the application view helpers directory? Or should the application find it at our own custom library directory?
Fix … it’s easy.
Make the following extra line of config in your application config file
cache.classFileIncludeCache = APPLICATION_PATH "/../data/pluginLoaderCache.php"
Add the following code to your Bootstrap.php
/**
* Setup include file cache to increase performance
*
* @return void
* @author Jim Li
*/
protected function _initFileInlcudeCache()
{
$classFileIncCacheOptions = $this->getOption('cache');
$classFileIncCache = $classFileIncCacheOptions['classFileIncludeCache'];
if(file_exists($classFileIncCache)) {
include_once $classFileIncCache;
}
Zend_Loader_PluginLoader::setIncludeFileCache($classFileIncCache);
}
Attention: make sure the “/data/” directory is writable by your web server.
Reference
Related posts:
- Zend Framework integrate with Symfony DI Container
- My Zend Framework project setup
- Zend Framework on shared host
- Common library files organization in ZF
- MVC & Zend Framework
Categories: PHP - Zend Framework
