You are here

class PhpFileCache in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/doctrine/cache/lib/Doctrine/Common/Cache/PhpFileCache.php \Doctrine\Common\Cache\PhpFileCache

Php file cache driver.

@since 2.3 @author Fabio B. Silva <fabio.bat.silva@gmail.com>

Hierarchy

Expanded class hierarchy of PhpFileCache

1 file declares its use of PhpFileCache
PhpFileCacheTest.php in vendor/doctrine/cache/tests/Doctrine/Tests/Common/Cache/PhpFileCacheTest.php

File

vendor/doctrine/cache/lib/Doctrine/Common/Cache/PhpFileCache.php, line 28

Namespace

Doctrine\Common\Cache
View source
class PhpFileCache extends FileCache {
  const EXTENSION = '.doctrinecache.php';

  /**
   * {@inheritdoc}
   */
  public function __construct($directory, $extension = self::EXTENSION, $umask = 02) {
    parent::__construct($directory, $extension, $umask);
  }

  /**
   * {@inheritdoc}
   */
  protected function doFetch($id) {
    $value = $this
      ->includeFileForId($id);
    if (!$value) {
      return false;
    }
    if ($value['lifetime'] !== 0 && $value['lifetime'] < time()) {
      return false;
    }
    return $value['data'];
  }

  /**
   * {@inheritdoc}
   */
  protected function doContains($id) {
    $value = $this
      ->includeFileForId($id);
    if (!$value) {
      return false;
    }
    return $value['lifetime'] === 0 || $value['lifetime'] > time();
  }

  /**
   * {@inheritdoc}
   */
  protected function doSave($id, $data, $lifeTime = 0) {
    if ($lifeTime > 0) {
      $lifeTime = time() + $lifeTime;
    }
    if (is_object($data) && !method_exists($data, '__set_state')) {
      throw new \InvalidArgumentException("Invalid argument given, PhpFileCache only allows objects that implement __set_state() " . "and fully support var_export(). You can use the FilesystemCache to save arbitrary object " . "graphs using serialize()/deserialize().");
    }
    $filename = $this
      ->getFilename($id);
    $value = array(
      'lifetime' => $lifeTime,
      'data' => $data,
    );
    $value = var_export($value, true);
    $code = sprintf('<?php return %s;', $value);
    return $this
      ->writeFile($filename, $code);
  }

  /**
   * @param string $id
   *
   * @return array|false
   */
  private function includeFileForId($id) {
    $fileName = $this
      ->getFilename($id);

    // note: error suppression is still faster than `file_exists`, `is_file` and `is_readable`
    $value = @(include $fileName);
    if (!isset($value['lifetime'])) {
      return false;
    }
    return $value;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Cache::STATS_HITS constant
Cache::STATS_MEMORY_AVAILABLE constant
Cache::STATS_MEMORY_AVAILIABLE constant Only for backward compatibility (may be removed in next major release)
Cache::STATS_MEMORY_USAGE constant
Cache::STATS_MISSES constant
Cache::STATS_UPTIME constant
CacheProvider::$namespace private property The namespace to prefix all cache ids with.
CacheProvider::$namespaceVersion private property The namespace version.
CacheProvider::contains public function Tests if an entry exists in the cache. Overrides Cache::contains
CacheProvider::delete public function Deletes a cache entry. Overrides Cache::delete
CacheProvider::deleteAll public function Deletes all cache entries in the current cache namespace. Overrides ClearableCache::deleteAll
CacheProvider::DOCTRINE_NAMESPACE_CACHEKEY constant
CacheProvider::doFetchMultiple protected function Default implementation of doFetchMultiple. Each driver that supports multi-get should owerwrite it. 4
CacheProvider::fetch public function Fetches an entry from the cache. Overrides Cache::fetch
CacheProvider::fetchMultiple public function Returns an associative array of values for keys is found in cache. Overrides MultiGetCache::fetchMultiple
CacheProvider::flushAll public function Flushes all cache entries, globally. Overrides FlushableCache::flushAll
CacheProvider::getNamespace public function Retrieves the namespace that prefixes all cache ids.
CacheProvider::getNamespaceCacheKey private function Returns the namespace cache key.
CacheProvider::getNamespacedId private function Prefixes the passed id with the configured namespace value.
CacheProvider::getNamespaceVersion private function Returns the namespace version.
CacheProvider::getStats public function Retrieves cached information from the data store. Overrides Cache::getStats
CacheProvider::save public function Puts data into the cache. Overrides Cache::save
CacheProvider::setNamespace public function Sets the namespace to prefix all cache ids with. 1
FileCache::$directory protected property The cache directory.
FileCache::$disallowedCharacterPatterns private property
FileCache::$extension private property The cache file extension.
FileCache::$replacementCharacters private property
FileCache::$umask private property
FileCache::createPathIfNeeded private function Create path if needed.
FileCache::doDelete protected function Deletes a cache entry. Overrides CacheProvider::doDelete
FileCache::doFlush protected function Flushes all cache entries. Overrides CacheProvider::doFlush
FileCache::doGetStats protected function Retrieves cached information from the data store. Overrides CacheProvider::doGetStats
FileCache::getDirectory public function Gets the cache directory.
FileCache::getExtension public function Gets the cache file extension.
FileCache::getFilename protected function
FileCache::getIterator private function
FileCache::writeFile protected function Writes a string content to file in an atomic way.
PhpFileCache::doContains protected function Tests if an entry exists in the cache. Overrides CacheProvider::doContains
PhpFileCache::doFetch protected function Fetches an entry from the cache. Overrides CacheProvider::doFetch
PhpFileCache::doSave protected function Puts data into the cache. Overrides CacheProvider::doSave
PhpFileCache::EXTENSION constant
PhpFileCache::includeFileForId private function
PhpFileCache::__construct public function Constructor. Overrides FileCache::__construct