Php file cache driver.
@since 2.3 @author Fabio B. Silva <fabio.bat.silva@gmail.com>
Expanded class hierarchy of PhpFileCache
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);
}
}
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:: |
constant | |||
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 | 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 | |
PhpFileCache:: |
protected | property |
Overrides FileCache:: |
|
PhpFileCache:: |
protected | function |
Test if an entry exists in the cache. Overrides CacheProvider:: |
|
PhpFileCache:: |
protected | function |
Fetches an entry from the cache. Overrides CacheProvider:: |
|
PhpFileCache:: |
protected | function |
Puts data into the cache. Overrides CacheProvider:: |
|
PhpFileCache:: |
constant |