PHP Класс 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.
С версии: 3.0
Автор: Qiang Xue ([email protected])
Наследование: extends Prado\TModule, implements Prado\Caching\ICache, implements ArrayAccess
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
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 )

Защищенные методы

Метод Описание
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.

Описание методов

add() публичный Метод

Nothing will be done if the cache already contains the key or if value is empty.
public add ( $id, $value, $expire, $dependency = null ) : boolean
Результат boolean true if the value is successfully stored into cache, false otherwise

addValue() абстрактный защищенный Метод

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
Результат boolean true if the value is successfully stored into cache, false otherwise

delete() публичный Метод

Deletes a value with the specified key from cache
public delete ( $id ) : boolean
Результат boolean if no error happens during deletion

deleteValue() абстрактный защищенный Метод

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
Результат boolean if no error happens during deletion

flush() публичный Метод

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 generateUniqueKey ( $key ) : sring
Результат sring a key generated from the provided key which ensures the uniqueness across applications

get() публичный Метод

Retrieves a value from cache with a specified key.
public get ( $id ) : mixed
Результат mixed the value stored in cache, false if the value is not in the cache or expired.

getKeyPrefix() публичный Метод

public getKeyPrefix ( ) : string
Результат 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 getPrimaryCache ( ) : boolean
Результат 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() абстрактный защищенный Метод

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
Результат string the value stored in cache, false if the value is not in the cache or expired.

init() публичный Метод

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

offsetExists() публичный Метод

This method is required by the interface \ArrayAccess.
public offsetExists ( $id ) : boolean
Результат boolean

offsetGet() публичный Метод

This method is required by the interface \ArrayAccess.
public offsetGet ( $id ) : mixed
Результат mixed the value stored in cache, false if the value is not in the cache or expired.

offsetSet() публичный Метод

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() публичный Метод

Deletes the value with the specified key from cache This method is required by the interface \ArrayAccess.
public offsetUnset ( $id ) : boolean
Результат boolean if no error happens during deletion

set() публичный Метод

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
Результат boolean true if the value is successfully stored into cache, false otherwise

setKeyPrefix() публичный Метод

public setKeyPrefix ( $value )

setPrimaryCache() публичный Метод

См. также: getPrimaryCache
public setPrimaryCache ( $value )

setValue() абстрактный защищенный Метод

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
Результат boolean true if the value is successfully stored into cache, false otherwise