You are here

ApcuClassLoader.php in X Autoload 7.5

File

src/ClassLoader/ApcuClassLoader.php
View source
<?php

namespace Drupal\xautoload\ClassLoader;

use Drupal\xautoload\CacheManager\CacheManagerObserverInterface;
use Drupal\xautoload\ClassFinder\InjectedApi\LoadClassGetFileInjectedApi;
class ApcuClassLoader extends AbstractCachedClassLoader implements CacheManagerObserverInterface {

  /**
   * @return bool
   */
  protected function checkRequirements() {
    return extension_loaded('apcu') && function_exists('apcu_store');
  }

  /**
   * {@inheritdoc}
   */
  function loadClass($class) {

    // Look if the cache has anything for this class.
    if ($file = \apcu_fetch($this->prefix . $class)) {
      if (is_file($file)) {
        require $file;
        return;
      }
      \apcu_delete($this->prefix . $class);
    }

    // Resolve cache miss.
    $api = new LoadClassGetFileInjectedApi($class);
    if ($this->finder
      ->apiFindFile($api, $class)) {
      \apcu_store($this->prefix . $class, $api
        ->getFile());
    }
  }

}

Classes

Namesort descending Description
ApcuClassLoader