You are here

WinCacheClassLoader.php in X Autoload 7.4

File

lib/ClassLoader/WinCacheClassLoader.php
View source
<?php

namespace Drupal\xautoload\ClassLoader;

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

  /**
   * @throws \Exception
   *   Throws an exception, if requirements are not satisfied.
   */
  protected function checkRequirements() {
    return extension_loaded('wincache') && function_exists('wincache_ucache_get');
  }

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

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

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

}

Classes