class FilesystemCache

Filesystem cache driver.

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

Hierarchy

Expanded class hierarchy of FilesystemCache

1 file declares its use of FilesystemCache
FilesystemCacheTest.php in drupal/core/vendor/doctrine/common/tests/Doctrine/Tests/Common/Cache/FilesystemCacheTest.php

File

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

Namespace

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

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

  /**
   * {@inheritdoc}
   */
  protected function doFetch($id) {
    $data = '';
    $lifetime = -1;
    $filename = $this
      ->getFilename($id);
    if (!file_exists($filename)) {
      return false;
    }
    $resource = fopen($filename, "r");
    if (false !== ($line = fgets($resource))) {
      $lifetime = (int) $line;
    }
    if ($lifetime !== 0 && $lifetime < time()) {
      fclose($resource);
      return false;
    }
    while (false !== ($line = fgets($resource))) {
      $data .= $line;
    }
    fclose($resource);
    return unserialize($data);
  }

  /**
   * {@inheritdoc}
   */
  protected function doContains($id) {
    $lifetime = -1;
    $filename = $this
      ->getFilename($id);
    if (!file_exists($filename)) {
      return false;
    }
    $resource = fopen($filename, "r");
    if (false !== ($line = fgets($resource))) {
      $lifetime = (int) $line;
    }
    fclose($resource);
    return $lifetime === 0 || $lifetime > time();
  }

  /**
   * {@inheritdoc}
   */
  protected function doSave($id, $data, $lifeTime = 0) {
    if ($lifeTime > 0) {
      $lifeTime = time() + $lifeTime;
    }
    $data = serialize($data);
    $filename = $this
      ->getFilename($id);
    $filepath = pathinfo($filename, PATHINFO_DIRNAME);
    if (!is_dir($filepath)) {
      mkdir($filepath, 0777, true);
    }
    return file_put_contents($filename, $lifeTime . PHP_EOL . $data);
  }

}

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
FilesystemCache::$extension protected property Overrides FileCache::$extension
FilesystemCache::doContains protected function Test if an entry exists in the cache. Overrides CacheProvider::doContains
FilesystemCache::doFetch protected function Fetches an entry from the cache. Overrides CacheProvider::doFetch
FilesystemCache::doSave protected function Puts data into the cache. Overrides CacheProvider::doSave
FilesystemCache::EXTENSION constant