class 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 drupal/core/vendor/doctrine/common/tests/Doctrine/Tests/Common/Cache/PhpFileCacheTest.php

File

drupal/core/vendor/doctrine/common/lib/Doctrine/Common/Cache/PhpFileCache.php, line 29

Namespace

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

  /**
   * {@inheritdoc}
   */
  protected $extension = self::EXTENSION;

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

  /**
   * {@inheritdoc}
   */
  protected function doContains($id) {
    $filename = $this
      ->getFilename($id);
    if (!file_exists($filename)) {
      return false;
    }
    $value = (include $filename);
    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);
    $filepath = pathinfo($filename, PATHINFO_DIRNAME);
    if (!is_dir($filepath)) {
      mkdir($filepath, 0777, true);
    }
    $value = array(
      'lifetime' => $lifeTime,
      'data' => $data,
    );
    $value = var_export($value, true);
    $code = sprintf('<?php return %s;', $value);
    return file_put_contents($filename, $code);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Cache::STATS_HITS constant
Cache::STATS_MEMORY_AVAILIABLE constant
Cache::STATS_MEMORY_USAGE constant
Cache::STATS_MISSES constant
Cache::STATS_UPTIME constant
CacheProvider::$namespace private property
CacheProvider::$namespaceVersion private property
CacheProvider::contains public function Test 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 Delete all cache entries.
CacheProvider::DOCTRINE_NAMESPACE_CACHEKEY constant
CacheProvider::fetch public function Fetches an entry from the cache. Overrides Cache::fetch
CacheProvider::flushAll public function Deletes all cache entries.
CacheProvider::getNamespace public function Retrieve the namespace that prefixes all cache ids.
CacheProvider::getNamespaceCacheKey private function Namespace cache key
CacheProvider::getNamespacedId private function Prefix the passed id with the configured namespace value
CacheProvider::getNamespaceVersion private function Namespace version
CacheProvider::getStats public function Retrieves cached information from data store Overrides Cache::getStats
CacheProvider::save public function Puts data into the cache. Overrides Cache::save
CacheProvider::setNamespace public function Set the namespace to prefix all cache ids with.
FileCache::$directory protected property
FileCache::doDelete protected function Deletes a cache entry. Overrides CacheProvider::doDelete
FileCache::doFlush protected function Deletes all cache entries. Overrides CacheProvider::doFlush
FileCache::doGetStats protected function Retrieves cached information from 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::__construct public function Constructor
PhpFileCache::$extension protected property Overrides FileCache::$extension
PhpFileCache::doContains protected function Test 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