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

Share this article on:
  • Facebook
  • Twitter
  • Google Bookmarks
  • Digg
  • del.icio.us
  • LinkedIn
  • MySpace
  • email
  • Live
  • Reddit
  • RSS
  • StumbleUpon

Related posts:

  1. Zend Framework integrate with Symfony DI Container
  2. My Zend Framework project setup
  3. Zend Framework on shared host
  4. Common library files organization in ZF
  5. MVC & Zend Framework
Categories: PHP - Zend Framework