Base class for cache provider implementations.
@since 2.2 @author Benjamin Eberlei <kontakt@beberlei.de> @author Guilherme Blanco <guilhermeblanco@hotmail.com> @author Jonathan Wage <jonwage@gmail.com> @author Roman Borschel <roman@code-factory.org> @author Fabio B. Silva <fabio.bat.silva@gmail.com>
Expanded class hierarchy of CacheProvider
abstract class CacheProvider implements Cache {
const DOCTRINE_NAMESPACE_CACHEKEY = 'DoctrineNamespaceCacheKey[%s]';
/**
* @var string The namespace to prefix all cache ids with
*/
private $namespace = '';
/**
* @var string The namespace version
*/
private $namespaceVersion;
/**
* Set the namespace to prefix all cache ids with.
*
* @param string $namespace
* @return void
*/
public function setNamespace($namespace) {
$this->namespace = (string) $namespace;
}
/**
* Retrieve the namespace that prefixes all cache ids.
*
* @return string
*/
public function getNamespace() {
return $this->namespace;
}
/**
* {@inheritdoc}
*/
public function fetch($id) {
return $this
->doFetch($this
->getNamespacedId($id));
}
/**
* {@inheritdoc}
*/
public function contains($id) {
return $this
->doContains($this
->getNamespacedId($id));
}
/**
* {@inheritdoc}
*/
public function save($id, $data, $lifeTime = 0) {
return $this
->doSave($this
->getNamespacedId($id), $data, $lifeTime);
}
/**
* {@inheritdoc}
*/
public function delete($id) {
return $this
->doDelete($this
->getNamespacedId($id));
}
/**
* {@inheritdoc}
*/
public function getStats() {
return $this
->doGetStats();
}
/**
* Deletes all cache entries.
*
* @return boolean TRUE if the cache entries were successfully flushed, FALSE otherwise.
*/
public function flushAll() {
return $this
->doFlush();
}
/**
* Delete all cache entries.
*
* @return boolean TRUE if the cache entries were successfully deleted, FALSE otherwise.
*/
public function deleteAll() {
$namespaceCacheKey = $this
->getNamespaceCacheKey();
$namespaceVersion = $this
->getNamespaceVersion() + 1;
$this->namespaceVersion = $namespaceVersion;
return $this
->doSave($namespaceCacheKey, $namespaceVersion);
}
/**
* Prefix the passed id with the configured namespace value
*
* @param string $id The id to namespace
* @return string $id The namespaced id
*/
private function getNamespacedId($id) {
$namespaceVersion = $this
->getNamespaceVersion();
return sprintf('%s[%s][%s]', $this->namespace, $id, $namespaceVersion);
}
/**
* Namespace cache key
*
* @return string $namespaceCacheKey
*/
private function getNamespaceCacheKey() {
return sprintf(self::DOCTRINE_NAMESPACE_CACHEKEY, $this->namespace);
}
/**
* Namespace version
*
* @return string $namespaceVersion
*/
private function getNamespaceVersion() {
if (null !== $this->namespaceVersion) {
return $this->namespaceVersion;
}
$namespaceCacheKey = $this
->getNamespaceCacheKey();
$namespaceVersion = $this
->doFetch($namespaceCacheKey);
if (false === $namespaceVersion) {
$namespaceVersion = 1;
$this
->doSave($namespaceCacheKey, $namespaceVersion);
}
$this->namespaceVersion = $namespaceVersion;
return $this->namespaceVersion;
}
/**
* Fetches an entry from the cache.
*
* @param string $id cache id The id of the cache entry to fetch.
* @return string The cached data or FALSE, if no cache entry exists for the given id.
*/
protected abstract function doFetch($id);
/**
* Test if an entry exists in the cache.
*
* @param string $id cache id The cache id of the entry to check for.
* @return boolean TRUE if a cache entry exists for the given cache id, FALSE otherwise.
*/
protected abstract function doContains($id);
/**
* Puts data into the cache.
*
* @param string $id The cache id.
* @param string $data The cache entry/data.
* @param bool|int $lifeTime The lifetime. If != false, sets a specific lifetime for this
* cache entry (null => infinite lifeTime).
*
* @return boolean TRUE if the entry was successfully stored in the cache, FALSE otherwise.
*/
protected abstract function doSave($id, $data, $lifeTime = false);
/**
* Deletes a cache entry.
*
* @param string $id cache id
* @return boolean TRUE if the cache entry was successfully deleted, FALSE otherwise.
*/
protected abstract function doDelete($id);
/**
* Deletes all cache entries.
*
* @return boolean TRUE if the cache entry was successfully deleted, FALSE otherwise.
*/
protected abstract function doFlush();
/**
* Retrieves cached information from data store
*
* @since 2.2
* @return array An associative array with server's statistics if available, NULL otherwise.
*/
protected abstract function doGetStats();
}
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 | Deletes a cache entry. | 9 |
CacheProvider:: |
abstract protected | function | Fetches an entry from the cache. | 10 |
CacheProvider:: |
abstract protected | function | Deletes all cache entries. | 9 |
CacheProvider:: |
abstract protected | function | Retrieves cached information from data store | 9 |
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. |