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