Class \Prado\Caching\TCache
TCache is the base class for cache classes with different cache storage implementation.
TCache implements the interface ICache with the following methods,
- get() : retrieve the value with a key (if any) from cache
- set() : store the value with a key into cache
- add() : store the value only if cache does not have this key
- delete() : delete the value with the specified key from cache
- flush() : delete all values from cache
Each value is associated with an expiration time. The get() operation ensures that any expired value will not be returned. The expiration time by the number of seconds. A expiration time 0 represents never expire.
By definition, cache does not ensure the existence of a value even if it never expires. Cache is not meant to be an persistent storage.
Child classes must implement the following methods:
- getValue()
- setValue()
- addValue()
- deleteValue()
and optionally flush()
Since version 3.1.2, TCache implements the \ArrayAccess interface such that the cache acts as an array.
Class hierarchy
- \Prado\Caching\TCache implements ICache, ArrayAccess
- \Prado\TModule implements IModule
- \Prado\TApplicationComponent
- \Prado\TComponent
Since: 3.0
public
|
add(string $id, mixed $value[, int $expire = 0 ][, ICacheDependency $dependency = null ]) : bool
Stores a value identified by a key into cache if the cache does not contain this key.
Nothing will be done if the cache already contains the key or if value is empty. |
public
|
|
public
|
flush() : mixed
Deletes all values from cache.
Be careful of performing this operation if the cache is shared by multiple applications. Child classes may implement this method to realize the flush operation. |
public
|
|
public
|
|
public
|
|
public
|
init(TXmlElement $config) : mixed
Initializes the cache module.
This method initializes the cache key prefix and registers the cache module with the application if the cache is primary. |
public
|
offsetExists(string $id) : bool
Returns whether there is a cache entry with a specified key.
This method is required by the interface \ArrayAccess. |
public
|
offsetGet(string $id) : false|mixed
Retrieves the value from cache with a specified key.
This method is required by the interface \ArrayAccess. |
public
|
offsetSet(string $id, mixed $value) : void
Stores the value identified by a key into cache.
If the cache already contains such a key, the existing value will be replaced with the new ones. To add expiration and dependencies, use the set() method. This method is required by the interface \ArrayAccess. |
public
|
offsetUnset(string $id) : void
Deletes the value with the specified key from cache
This method is required by the interface \ArrayAccess.
|
public
|
set(string $id, mixed $value[, int $expire = 0 ][, ICacheDependency $dependency = null ]) : bool
Stores a value identified by a key into cache.
If the cache already contains such a key, the existing value and expiration time will be replaced with the new ones. If the value is empty, the cache key will be deleted. |
public
|
|
public
|
|
protected
abstract
|
addValue(string $key, string $value, int $expire) : bool
Stores a value identified by a key into cache if the cache does not contain this key.
This method should be implemented by child classes to store the data in specific cache storage. The uniqueness and dependency are handled in TCache::add() already. So only the implementation of data storage is needed. |
protected
abstract
|
deleteValue(string $key) : bool
Deletes a value with the specified key from cache
This method should be implemented by child classes to delete the data from actual cache storage.
|
protected
|
|
protected
abstract
|
getValue(string $key) : false|string
Retrieves a value from cache with a specified key.
This method should be implemented by child classes to store the data in specific cache storage. The uniqueness and dependency are handled in TCache::get() already. So only the implementation of data retrieval is needed. |
protected
abstract
|
setValue(string $key, string $value, int $expire) : bool
Stores a value identified by a key in cache.
This method should be implemented by child classes to store the data in specific cache storage. The uniqueness and dependency are handled in TCache::set() already. So only the implementation of data storage is needed. |
\Prado\TApplicationComponent::FX_CACHE_FILE, \Prado\TComponent::GLOBAL_RAISE_EVENT_LISTENER |