Packages:
default
System
System.Caching
System.Collections
System.Data
System.Data.ActiveRecord
System.Data.ActiveRecord.Relations
System.Data.ActiveRecord.Scaffold
System.Data.ActiveReecord.Scaffold.InputBuilder
System.Data.Commom.Sqlite
System.Data.Common
System.Data.Common.Mssql
System.Data.Common.Mysql
System.Data.Common.Oracle
System.Data.Common.Pgsql
System.Data.Common.Sqlite
System.Data.DataGateway
System.Data.SqlMap
System.Data.SqlMap.Configuration
System.Data.SqlMap.Statements
System.Exceptions
System.I18N
System.IO
System.Security
System.Util
System.Web
System.Web.Services
System.Web.UI
System.Web.UI.ActiveControls
System.Web.UI.WebControls
System.Web.UI.WebControls.assets
System.Xml


Classes:
Keyword

Class TCache

Direct Known Sub-classes:

TCache class

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:

and optionally 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 <qiang.xue@gmail.com>

Method Summary
boolean
add ( string $id, mixed $value, integer $expire, ICacheDependency $dependency)
Stores a value identified by a key into cache if the cache does not contain this key.
protected  abstract  boolean
addValue ( string $key, string $value, integer $expire)
Stores a value identified by a key into cache if the cache does not contain this key.
boolean
delete ( string $id)
Deletes a value with the specified key from cache
protected  abstract  boolean
deleteValue ( string $key)
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.
void
flush ()
Deletes all values from cache.
protected  sring
generateUniqueKey ( string $key)
mixed
get ( string $id)
Retrieves a value from cache with a specified key.
string
boolean
protected  abstract  string
getValue ( string $key)
Retrieves a value from cache with a specified key.
void
init ( TXmlElement $config)
Initializes the cache module.
boolean
offsetExists ( string $id)
Returns whether there is a cache entry with a specified key.
void
offsetGet ( mixed $id)
void
offsetSet ( mixed $id, mixed $value)
void
offsetUnset ( mixed $id)
boolean
set ( string $id, mixed $value, integer $expire, ICacheDependency $dependency)
Stores a value identified by a key into cache.
void
setKeyPrefix ( string $value)
void
setPrimaryCache ( boolean $value)
protected  abstract  boolean
setValue ( string $key, string $value, integer $expire)
Stores a value identified by a key in cache.
Methods Inherited From TModule
TModule::getID(), TModule::init(), TModule::setID()
Methods Inherited From TApplicationComponent
TApplicationComponent::getApplication(), TApplicationComponent::getRequest(), TApplicationComponent::getResponse(), TApplicationComponent::getService(), TApplicationComponent::getSession(), TApplicationComponent::getUser(), TApplicationComponent::publishAsset(), TApplicationComponent::publishFilePath()
Methods Inherited From TComponent
TComponent::addParsedObject(), TComponent::attachEventHandler(), TComponent::canGetProperty(), TComponent::canSetProperty(), TComponent::createdOnTemplate(), TComponent::detachEventHandler(), TComponent::evaluateExpression(), TComponent::evaluateStatements(), TComponent::getEventHandlers(), TComponent::getSubProperty(), TComponent::hasEvent(), TComponent::hasEventHandler(), TComponent::hasProperty(), TComponent::raiseEvent(), TComponent::setSubProperty(), TComponent::__get(), TComponent::__set()

Method Details

add

public boolean add (string $id , mixed $value , integer $expire , ICacheDependency $dependency )

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.

Input
string$idthe key identifying the value to be cached
mixed$valuethe value to be cached
integer$expirethe number of seconds in which the cached value will expire. 0 means never expire.
ICacheDependency$dependencydependency of the cached item. If the dependency changes, the item is labeled invalid.
Output
boolean true if the value is successfully stored into cache, false otherwise
Exception

addValue

protected abstract boolean addValue (string $key , string $value , integer $expire )

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 add() already. So only the implementation of data storage is needed.

Input
string$keythe key identifying the value to be cached
string$valuethe value to be cached
integer$expirethe number of seconds in which the cached value will expire. 0 means never expire.
Output
boolean true if the value is successfully stored into cache, false otherwise
Exception

delete

public boolean delete (string $id )

Deletes a value with the specified key from cache

Input
string$idthe key of the value to be deleted
Output
boolean if no error happens during deletion
Exception

deleteValue

protected abstract boolean deleteValue (string $key )

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.

Input
string$keythe key of the value to be deleted
Output
boolean if no error happens during deletion
Exception

flush

public void flush ()

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.

Output
Exception
throwsTNotSupportedException if this method is not overridden by child classes

generateUniqueKey

protected sring generateUniqueKey (string $key )

Input
string$keya key identifying a value to be cached
Output
sring a key generated from the provided key which ensures the uniqueness across applications
Exception

get

public mixed get (string $id )

Retrieves a value from cache with a specified key.

Input
string$ida key identifying the cached value
Output
mixed the value stored in cache, false if the value is not in the cache or expired.
Exception

getKeyPrefix

public string getKeyPrefix ()

Output
string a unique prefix for the keys of cached values. If it is not explicitly set, it will take the value of TApplication::getUniqueID.
Exception

getPrimaryCache

public boolean getPrimaryCache ()

Output
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.
Exception

getValue

protected abstract string getValue (string $key )

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 get() already. So only the implementation of data retrieval is needed.

Input
string$keya unique key identifying the cached value
Output
string the value stored in cache, false if the value is not in the cache or expired.
Exception

init

public void init (TXmlElement $config )

Initializes the cache module.

This method initializes the cache key prefix and registers the cache module with the application if the cache is primary.

Input
TXmlElement$configthe module configuration
Output
Exception

offsetExists

public boolean offsetExists (string $id )

Returns whether there is a cache entry with a specified key.

This method is required by the interface ArrayAccess.

Input
string$ida key identifying the cached value
Output
Exception

offsetGet

public void offsetGet (mixed $id )

Input
mixed$id
Output
Exception

offsetSet

public void offsetSet (mixed $id , mixed $value )

Input
mixed$id
mixed$value
Output
Exception

offsetUnset

public void offsetUnset (mixed $id )

Input
mixed$id
Output
Exception

set

public boolean set (string $id , mixed $value , integer $expire , ICacheDependency $dependency )

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.

Input
string$idthe key identifying the value to be cached
mixed$valuethe value to be cached
integer$expirethe number of seconds in which the cached value will expire. 0 means never expire.
ICacheDependency$dependencydependency of the cached item. If the dependency changes, the item is labeled invalid.
Output
boolean true if the value is successfully stored into cache, false otherwise
Exception

setKeyPrefix

public void setKeyPrefix (string $value )

Input
string$valuea unique prefix for the keys of cached values
Output
Exception

setPrimaryCache

public void setPrimaryCache (boolean $value )

Input
boolean$valuewhether this cache module is used as primary/system cache. Defaults to false.
Output
Exception

setValue

protected abstract boolean setValue (string $key , string $value , integer $expire )

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 set() already. So only the implementation of data storage is needed.

Input
string$keythe key identifying the value to be cached
string$valuethe value to be cached
integer$expirethe number of seconds in which the cached value will expire. 0 means never expire.
Output
boolean true if the value is successfully stored into cache, false otherwise
Exception