You are here

class xautoload_ClassLoader_ApcCache in X Autoload 7.3

Hierarchy

Expanded class hierarchy of xautoload_ClassLoader_ApcCache

File

lib/ClassLoader/ApcCache.php, line 4

View source
class xautoload_ClassLoader_ApcCache extends xautoload_ClassLoader_NoCache {

  /**
   * @var string
   */
  protected $prefix;

  /**
   * @param xautoload_ClassFinder_Interface $finder
   *   Another ClassFinder to delegate to, if the class is not in the cache.
   * @param string $prefix
   *   A prefix for the storage key in APC.
   * @throws Exception
   */
  function __construct($finder, $prefix) {
    if (!extension_loaded('apc') || !function_exists('apc_store')) {
      throw new Exception('Unable to use xautoload_ClassLoader_ApcCache, because APC is not enabled.');
    }
    $this->prefix = $prefix;
    parent::__construct($finder);
  }

  /**
   * Set the APC prefix after a flush cache.
   *
   * @param string $prefix
   *   A prefix for the storage key in APC.
   */
  function setApcPrefix($prefix) {
    $this->prefix = $prefix;
  }

  /**
   * Callback for class loading. This will include ("require") the file found.
   *
   * @param string $class
   *   The class to load.
   */
  function loadClass($class) {
    if ($file = $this
      ->findFile($class)) {
      require $file;
    }
  }

  /**
   * For compatibility, it is possible to use the class loader as a finder.
   *
   * @param string $class
   *   The class to find.
   *
   * @return string
   *   File where the class is assumed to be.
   */
  function findFile($class) {
    if (FALSE === ($file = apc_fetch($this->prefix . $class)) || !empty($file) && !is_file($file)) {

      // Resolve cache miss.
      if ($file = parent::findFile($class)) {
        apc_store($this->prefix . $class, $file);
      }
    }
    return $file;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
xautoload_ClassLoader_ApcCache::$prefix protected property
xautoload_ClassLoader_ApcCache::findFile function For compatibility, it is possible to use the class loader as a finder. Overrides xautoload_ClassLoader_NoCache::findFile 1
xautoload_ClassLoader_ApcCache::loadClass function Callback for class loading. This will include ("require") the file found. Overrides xautoload_ClassLoader_NoCache::loadClass
xautoload_ClassLoader_ApcCache::setApcPrefix function Set the APC prefix after a flush cache.
xautoload_ClassLoader_ApcCache::__construct function Overrides xautoload_ClassLoader_NoCache::__construct
xautoload_ClassLoader_NoCache::$finder protected property
xautoload_ClassLoader_NoCache::register function Registers this instance as an autoloader. Overrides xautoload_ClassLoader_Interface::register
xautoload_ClassLoader_NoCache::setFinder function Replace the finder with another one.
xautoload_ClassLoader_NoCache::unregister function Unregister from the spl autoload stack. Overrides xautoload_ClassLoader_Interface::unregister