class ChainCache in Plug 7
Cache provider that allows to easily chain multiple cache providers
@author Michaël Gallego <mic.gallego@gmail.com>
Hierarchy
- class \Doctrine\Common\Cache\CacheProvider implements Cache, ClearableCache, FlushableCache, MultiGetCache
- class \Doctrine\Common\Cache\ChainCache
Expanded class hierarchy of ChainCache
1 file declares its use of ChainCache
- ChainCacheTest.php in lib/
doctrine/ cache/ tests/ Doctrine/ Tests/ Common/ Cache/ ChainCacheTest.php
File
- lib/
doctrine/ cache/ lib/ Doctrine/ Common/ Cache/ ChainCache.php, line 27
Namespace
Doctrine\Common\CacheView source
class ChainCache extends CacheProvider {
/**
* @var CacheProvider[]
*/
private $cacheProviders = array();
/**
* Constructor
*
* @param CacheProvider[] $cacheProviders
*/
public function __construct($cacheProviders = array()) {
$this->cacheProviders = $cacheProviders;
}
/**
* {@inheritDoc}
*/
public function setNamespace($namespace) {
parent::setNamespace($namespace);
foreach ($this->cacheProviders as $cacheProvider) {
$cacheProvider
->setNamespace($namespace);
}
}
/**
* {@inheritDoc}
*/
protected function doFetch($id) {
foreach ($this->cacheProviders as $key => $cacheProvider) {
if ($cacheProvider
->doContains($id)) {
$value = $cacheProvider
->doFetch($id);
// We populate all the previous cache layers (that are assumed to be faster)
for ($subKey = $key - 1; $subKey >= 0; $subKey--) {
$this->cacheProviders[$subKey]
->doSave($id, $value);
}
return $value;
}
}
return false;
}
/**
* {@inheritDoc}
*/
protected function doContains($id) {
foreach ($this->cacheProviders as $cacheProvider) {
if ($cacheProvider
->doContains($id)) {
return true;
}
}
return false;
}
/**
* {@inheritDoc}
*/
protected function doSave($id, $data, $lifeTime = 0) {
$stored = true;
foreach ($this->cacheProviders as $cacheProvider) {
$stored = $cacheProvider
->doSave($id, $data, $lifeTime) && $stored;
}
return $stored;
}
/**
* {@inheritDoc}
*/
protected function doDelete($id) {
$deleted = true;
foreach ($this->cacheProviders as $cacheProvider) {
$deleted = $cacheProvider
->doDelete($id) && $deleted;
}
return $deleted;
}
/**
* {@inheritDoc}
*/
protected function doFlush() {
$flushed = true;
foreach ($this->cacheProviders as $cacheProvider) {
$flushed = $cacheProvider
->doFlush() && $flushed;
}
return $flushed;
}
/**
* {@inheritDoc}
*/
protected function doGetStats() {
// We return all the stats from all adapters
$stats = array();
foreach ($this->cacheProviders as $cacheProvider) {
$stats[] = $cacheProvider
->doGetStats();
}
return $stats;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Cache:: |
constant | |||
Cache:: |
constant | |||
Cache:: |
constant | Only for backward compatibility (may be removed in next major release) | ||
Cache:: |
constant | |||
Cache:: |
constant | |||
Cache:: |
constant | |||
CacheProvider:: |
private | property | The namespace to prefix all cache ids with. | |
CacheProvider:: |
private | property | The namespace version. | |
CacheProvider:: |
public | function |
Tests if an entry exists in the cache. Overrides Cache:: |
|
CacheProvider:: |
public | function |
Deletes a cache entry. Overrides Cache:: |
|
CacheProvider:: |
public | function |
Deletes all cache entries. Overrides ClearableCache:: |
|
CacheProvider:: |
constant | |||
CacheProvider:: |
protected | function | Default implementation of doFetchMultiple. Each driver that supports multi-get should owerwrite it. | 4 |
CacheProvider:: |
public | function |
Fetches an entry from the cache. Overrides Cache:: |
|
CacheProvider:: |
public | function |
Returns an associative array of values for keys is found in cache. Overrides MultiGetCache:: |
|
CacheProvider:: |
public | function |
Flushes all cache entries. Overrides FlushableCache:: |
|
CacheProvider:: |
public | function | Retrieves the namespace that prefixes all cache ids. | |
CacheProvider:: |
private | function | Returns the namespace cache key. | |
CacheProvider:: |
private | function | Prefixes the passed id with the configured namespace value. | |
CacheProvider:: |
private | function | Returns the namespace version. | |
CacheProvider:: |
public | function |
Retrieves cached information from the data store. Overrides Cache:: |
|
CacheProvider:: |
public | function |
Puts data into the cache. Overrides Cache:: |
|
ChainCache:: |
private | property | ||
ChainCache:: |
protected | function |
Tests if an entry exists in the cache. Overrides CacheProvider:: |
|
ChainCache:: |
protected | function |
Deletes a cache entry. Overrides CacheProvider:: |
|
ChainCache:: |
protected | function |
Fetches an entry from the cache. Overrides CacheProvider:: |
|
ChainCache:: |
protected | function |
Flushes all cache entries. Overrides CacheProvider:: |
|
ChainCache:: |
protected | function |
Retrieves cached information from the data store. Overrides CacheProvider:: |
|
ChainCache:: |
protected | function |
Puts data into the cache. Overrides CacheProvider:: |
|
ChainCache:: |
public | function |
Sets the namespace to prefix all cache ids with. Overrides CacheProvider:: |
|
ChainCache:: |
public | function | Constructor |