PHP Class Prado\Caching\TCache

TCache is the base class for cache classes with different cache storage implementation. TCache implements the interface {@link ICache} with the following methods, - {@link get} : retrieve the value with a key (if any) from cache - {@link set} : store the value with a key into cache - {@link add} : store the value only if cache does not have this key - {@link delete} : delete the value with the specified key from cache - {@link flush} : delete all values from cache Each value is associated with an expiration time. The {@link 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: - {@link getValue} - {@link setValue} - {@link addValue} - {@link deleteValue} and optionally {@link flush} Since version 3.1.2, TCache implements the \ArrayAccess interface such that the cache acts as an array.
Since: 3.0
Author: Qiang Xue ([email protected])
Inheritance: extends Prado\TModule, implements Prado\Caching\ICache, implements ArrayAccess
Afficher le fichier Open project: pradosoft/prado Class Usage Examples

Méthodes publiques

Méthode Description
add ( $id, $value, $expire, $dependency = null ) : boolean Stores a value identified by a key into cache if the cache does not contain this key.
delete ( $id ) : boolean Deletes a value with the specified key from cache
flush ( ) Deletes all values from cache.
get ( $id ) : mixed Retrieves a value from cache with a specified key.
getKeyPrefix ( ) : string
getPrimaryCache ( ) : boolean
init ( $config ) Initializes the cache module.
offsetExists ( $id ) : boolean Returns whether there is a cache entry with a specified key.
offsetGet ( $id ) : mixed Retrieves the value from cache with a specified key.
offsetSet ( $id, $value ) Stores the value identified by a key into cache.
offsetUnset ( $id ) : boolean Deletes the value with the specified key from cache This method is required by the interface \ArrayAccess.
set ( $id, $value, $expire, $dependency = null ) : boolean Stores a value identified by a key into cache.
setKeyPrefix ( $value )
setPrimaryCache ( $value )

Méthodes protégées

Méthode Description
addValue ( $key, $value, $expire ) : boolean Stores a value identified by a key into cache if the cache does not contain this key.
deleteValue ( $key ) : boolean 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.
generateUniqueKey ( $key ) : sring
getValue ( $key ) : string Retrieves a value from cache with a specified key.
setValue ( $key, $value, $expire ) : boolean Stores a value identified by a key in cache.

Method Details

add() public méthode

Nothing will be done if the cache already contains the key or if value is empty.
public add ( $id, $value, $expire, $dependency = null ) : boolean
Résultat boolean true if the value is successfully stored into cache, false otherwise

addValue() abstract protected méthode

This method should be implemented by child classes to store the data in specific cache storage. The uniqueness and dependency are handled in {@link add()} already. So only the implementation of data storage is needed.
abstract protected addValue ( $key, $value, $expire ) : boolean
Résultat boolean true if the value is successfully stored into cache, false otherwise

delete() public méthode

Deletes a value with the specified key from cache
public delete ( $id ) : boolean
Résultat boolean if no error happens during deletion

deleteValue() abstract protected méthode

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.
abstract protected deleteValue ( $key ) : boolean
Résultat boolean if no error happens during deletion

flush() public méthode

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 flush ( )

generateUniqueKey() protected méthode

protected generateUniqueKey ( $key ) : sring
Résultat sring a key generated from the provided key which ensures the uniqueness across applications

get() public méthode

Retrieves a value from cache with a specified key.
public get ( $id ) : mixed
Résultat mixed the value stored in cache, false if the value is not in the cache or expired.

getKeyPrefix() public méthode

public getKeyPrefix ( ) : string
Résultat string a unique prefix for the keys of cached values. If it is not explicitly set, it will take the value of {@link TApplication::getUniqueID}.

getPrimaryCache() public méthode

public getPrimaryCache ( ) : boolean
Résultat boolean whether this cache module is used as primary/system cache. A primary cache is used by PRADO core framework to cache data such as parsed templates, themes, etc.

getValue() abstract protected méthode

This method should be implemented by child classes to store the data in specific cache storage. The uniqueness and dependency are handled in {@link get()} already. So only the implementation of data retrieval is needed.
abstract protected getValue ( $key ) : string
Résultat string the value stored in cache, false if the value is not in the cache or expired.

init() public méthode

This method initializes the cache key prefix and registers the cache module with the application if the cache is primary.
public init ( $config )

offsetExists() public méthode

This method is required by the interface \ArrayAccess.
public offsetExists ( $id ) : boolean
Résultat boolean

offsetGet() public méthode

This method is required by the interface \ArrayAccess.
public offsetGet ( $id ) : mixed
Résultat mixed the value stored in cache, false if the value is not in the cache or expired.

offsetSet() public méthode

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 offsetSet ( $id, $value )

offsetUnset() public méthode

Deletes the value with the specified key from cache This method is required by the interface \ArrayAccess.
public offsetUnset ( $id ) : boolean
Résultat boolean if no error happens during deletion

set() public méthode

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 set ( $id, $value, $expire, $dependency = null ) : boolean
Résultat boolean true if the value is successfully stored into cache, false otherwise

setKeyPrefix() public méthode

public setKeyPrefix ( $value )

setPrimaryCache() public méthode

See also: getPrimaryCache
public setPrimaryCache ( $value )

setValue() abstract protected méthode

This method should be implemented by child classes to store the data in specific cache storage. The uniqueness and dependency are handled in {@link set()} already. So only the implementation of data storage is needed.
abstract protected setValue ( $key, $value, $expire ) : boolean
Résultat boolean true if the value is successfully stored into cache, false otherwise