Base file cache driver.
@since 2.3 @author Fabio B. Silva <fabio.bat.silva@gmail.com>
Expanded class hierarchy of FileCache
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;
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Cache:: |
constant | |||
Cache:: |
constant | |||
Cache:: |
constant | |||
Cache:: |
constant | |||
Cache:: |
constant | |||
CacheProvider:: |
private | property | ||
CacheProvider:: |
private | property | ||
CacheProvider:: |
public | function |
Test if an entry exists in the cache. Overrides Cache:: |
|
CacheProvider:: |
public | function |
Deletes a cache entry. Overrides Cache:: |
|
CacheProvider:: |
public | function | Delete all cache entries. | |
CacheProvider:: |
abstract protected | function | Test if an entry exists in the cache. | 10 |
CacheProvider:: |
constant | |||
CacheProvider:: |
abstract protected | function | Fetches an entry from the cache. | 10 |
CacheProvider:: |
abstract protected | function | Puts data into the cache. | 10 |
CacheProvider:: |
public | function |
Fetches an entry from the cache. Overrides Cache:: |
|
CacheProvider:: |
public | function | Deletes all cache entries. | |
CacheProvider:: |
public | function | Retrieve the namespace that prefixes all cache ids. | |
CacheProvider:: |
private | function | Namespace cache key | |
CacheProvider:: |
private | function | Prefix the passed id with the configured namespace value | |
CacheProvider:: |
private | function | Namespace version | |
CacheProvider:: |
public | function |
Retrieves cached information from data store Overrides Cache:: |
|
CacheProvider:: |
public | function |
Puts data into the cache. Overrides Cache:: |
|
CacheProvider:: |
public | function | Set the namespace to prefix all cache ids with. | |
FileCache:: |
protected | property | ||
FileCache:: |
protected | property | 2 | |
FileCache:: |
protected | function |
Deletes a cache entry. Overrides CacheProvider:: |
|
FileCache:: |
protected | function |
Deletes all cache entries. Overrides CacheProvider:: |
|
FileCache:: |
protected | function |
Retrieves cached information from data store Overrides CacheProvider:: |
|
FileCache:: |
public | function | Gets the cache directory. | |
FileCache:: |
public | function | Gets the cache file extension. | |
FileCache:: |
protected | function | ||
FileCache:: |
public | function | Constructor |