abstract class FileCache

Base file cache driver.

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

Hierarchy

Expanded class hierarchy of FileCache

File

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

Namespace

Doctrine\Common\Cache
View source
abstract class FileCache extends CacheProvider {

  /**
   * @var string Cache directory.
   */
  protected $directory;

  /**
   * @var string Cache file extension.
   */
  protected $extension;

  /**
   * Constructor
   *
   * @param string $directory Cache directory.
   * @param string $directory Cache file extension.
   *
   * @throws \InvalidArgumentException
   */
  public function __construct($directory, $extension = null) {
    if (!is_dir($directory) && !@mkdir($directory, 0777, true)) {
      throw new \InvalidArgumentException(sprintf('The directory "%s" does not exist and could not be created.', $directory));
    }
    if (!is_writable($directory)) {
      throw new \InvalidArgumentException(sprintf('The directory "%s" is not writable.', $directory));
    }
    $this->directory = realpath($directory);
    $this->extension = $extension ?: $this->extension;
  }

  /**
   * Gets the cache directory.
   *
   * @return string
   */
  public function getDirectory() {
    return $this->directory;
  }

  /**
   * Gets the cache file extension.
   *
   * @return string
   */
  public function getExtension() {
    return $this->extension;
  }

  /**
   * @return string
   */
  protected function getFilename($id) {
    $path = implode(str_split(md5($id), 12), DIRECTORY_SEPARATOR);
    $path = $this->directory . DIRECTORY_SEPARATOR . $path;
    return $path . DIRECTORY_SEPARATOR . $id . $this->extension;
  }

  /**
   * {@inheritdoc}
   */
  protected function doDelete($id) {
    return unlink($this
      ->getFilename($id));
  }

  /**
   * {@inheritdoc}
   */
  protected function doFlush() {
    $pattern = '/^.+\\' . $this->extension . '$/i';
    $iterator = new \RecursiveDirectoryIterator($this->directory);
    $iterator = new \RecursiveIteratorIterator($iterator);
    $iterator = new \RegexIterator($iterator, $pattern);
    foreach ($iterator as $name => $file) {
      unlink($name);
    }
    return true;
  }

  /**
   * {@inheritdoc}
   */
  protected function doGetStats() {
    return null;
  }

}

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