observeCachePrefix($loader); return $loader; } /** * {@inheritdoc} */ function loadClass($class) { // Look if the cache has anything for this class. if (isset($this->classFiles[$class])) { $file = $this->classFiles[$class]; // The is_file() check may cost around 0.0045 ms per class file, but this // depends on your system of course. if (is_file($file)) { require $file; return; } $this->toBeDeleted[$class] = $file; unset($this->classFiles[$class]); ++$this->n; } // Resolve cache miss. $api = new LoadClassGetFileInjectedApi($class); if ($this->finder->apiFindFile($api, $class)) { // Queue the result for the cache. $this->toBeAdded[$class] = $this->classFiles[$class] = $api->getFile(); ++$this->n; } // Save the cache if enough has been queued up. if ($this->n >= $this->nMax) { $this->classFiles = $this->updateClassFiles($this->toBeAdded, $this->toBeDeleted); $this->toBeDeleted = array(); $this->toBeAdded = array(); $this->nMax *= 2; $this->n = 0; } } /** * Set the new cache prefix after a flush cache. * * @param string $prefix * A prefix for the storage key in APC. */ function setCachePrefix($prefix) { $this->classFiles = $this->loadClassFiles($prefix); } /** * @param string $prefix * * @return string[] */ abstract protected function loadClassFiles($prefix); /** * @param string[] $toBeAdded * @param string[] $toBeRemoved * * @return string[] */ abstract protected function updateClassFiles($toBeAdded, $toBeRemoved); }