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
Mostrar archivo Open project: pradosoft/prado Class Usage Examples

Public Methods

Method 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 )

Protected Methods

Method 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 method

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

addValue() abstract protected method

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
return boolean true if the value is successfully stored into cache, false otherwise

delete() public method

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

deleteValue() abstract protected method

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
return boolean if no error happens during deletion

flush() public method

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 method

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

get() public method

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

getKeyPrefix() public method

public getKeyPrefix ( ) : string
return 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 method

public getPrimaryCache ( ) : boolean
return 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 method

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
return string the value stored in cache, false if the value is not in the cache or expired.

init() public method

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 method

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

offsetGet() public method

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

offsetSet() public method

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 method

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

set() public method

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
return boolean true if the value is successfully stored into cache, false otherwise

setKeyPrefix() public method

public setKeyPrefix ( $value )

setPrimaryCache() public method

See also: getPrimaryCache
public setPrimaryCache ( $value )

setValue() abstract protected method

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
return boolean true if the value is successfully stored into cache, false otherwise