## Class TCache

Description

Implements interfaces:

- ICache

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:

- getValue
- setValue
- addValue
- deleteValue

and optionally flush

- abstract:
- since: 3.0
- version: $Id: TCache.php 1565 2006-12-05 20:38:18Z xue $
- author: Qiang Xue <qiang.xue@gmail.com>

Located in /Caching/TCache.php (line 46)

    TComponent
       |
       --TApplicationComponent
          |
          --TModule
             |
             --TCache

Direct descendents

Class | Description
--- | ---
TAPCCache | TAPCCache class
TMemCache | TMemCache class
TSqliteCache | TSqliteCache class

Method Summary
boolean add (string $id, mixed $value, integer $expire, [ICacheDependency $dependency = null])
boolean addValue (string $key, string $value, integer $expire)
boolean delete (string $id)
boolean deleteValue (string $key)
void flush ()
sring generateUniqueKey (string $key)
mixed get (string $id)
string getKeyPrefix ()
boolean getPrimaryCache ()
string getValue (string $key)
void init (TXmlElement $config)
boolean set (string $id, mixed $value, integer $expire, [ICacheDependency $dependency = null])
void setKeyPrefix (string $value)
void setPrimaryCache (boolean $value)
boolean setValue (string $key, string $value, integer $expire)
Methods
add (line 158)

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.

- return: true if the value is successfully stored into cache, false otherwise
- access: public

boolean add (string $id, mixed $value, integer $expire, [ICacheDependency $dependency = null])

- string $id: the key identifying the value to be cached
- mixed $value: the value to be cached
- integer $expire: the number of seconds in which the cached value will expire. 0 means never expire.
- ICacheDependency $dependency: dependency of the cached item. If the dependency changes, the item is labelled invalid.

addValue (line 223)

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.

- return: true if the value is successfully stored into cache, false otherwise
- access: protected
- abstract:

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

- string $key: the key identifying the value to be cached
- string $value: the value to be cached
- integer $expire: the number of seconds in which the cached value will expire. 0 means never expire.

Redefined in descendants as:

- TAPCCache::addValue() : Stores a value identified by a key into cache if the cache does not contain this key.
- TMemCache::addValue() : Stores a value identified by a key into cache if the cache does not contain this key.
- TSqliteCache::addValue() : Stores a value identified by a key into cache if the cache does not contain this key.

delete (line 170)

Deletes a value with the specified key from cache

- return: if no error happens during deletion
- access: public

boolean delete (string $id)

- string $id: the key of the value to be deleted

deleteValue (line 231)

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.

- return: if no error happens during deletion
- access: protected
- abstract:

boolean deleteValue (string $key)

- string $key: the key of the value to be deleted

Redefined in descendants as:

- TAPCCache::deleteValue() : Deletes a value with the specified key from cache This is the implementation of the method declared in the parent class.
- TMemCache::deleteValue() : Deletes a value with the specified key from cache This is the implementation of the method declared in the parent class.
- TSqliteCache::deleteValue() : Deletes a value with the specified key from cache This is the implementation of the method declared in the parent class.

flush (line 181)

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.

- access: public
- throws: TNotSupportedException if this method is not overriden by child classes

void flush ()

Redefined in descendants as:

- TAPCCache::flush() : Deletes all values from cache.
- TMemCache::flush() : Deletes all values from cache.
- TSqliteCache::flush() : Deletes all values from cache.

generateUniqueKey (line 110)

- return: a key generated from the provided key which ensures the uniqueness across applications
- access: protected

sring generateUniqueKey (string $key)

- string $key: a key identifying a value to be cached

get (line 120)

Retrieves a value from cache with a specified key.

- return: the value stored in cache, false if the value is not in the cache or expired.
- access: public

mixed get (string $id)

- string $id: a key identifying the cached value

getKeyPrefix (line 93)

- return: a unique prefix for the keys of cached values. If it is not explicitly set, it will take the value of TApplication::getUniqueID.
- access: public

string getKeyPrefix ()
getPrimaryCache (line 75)

- return: 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.
- access: public

boolean getPrimaryCache ()
getValue (line 195)

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.

- return: the value stored in cache, false if the value is not in the cache or expired.
- access: protected
- abstract:

string getValue (string $key)

- string $key: a unique key identifying the cached value

Redefined in descendants as:

- TAPCCache::getValue() : Retrieves a value from cache with a specified key.
- TMemCache::getValue() : Retrieves a value from cache with a specified key.
- TSqliteCache::getValue() : Retrieves a value from cache with a specified key.

init (line 57)

Initializes the cache module.

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

- access: public

void init (TXmlElement $config)

- TXmlElement $config: the module configuration

Redefinition of:

TModule::init()
  Initializes the module.

Redefined in descendants as:

- TAPCCache::init() : Initializes this module.
- TMemCache::init() : Initializes this module.
- TSqliteCache::init() : Initializes this module.

set (line 142)

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.

- return: true if the value is successfully stored into cache, false otherwise
- access: public

boolean set (string $id, mixed $value, integer $expire, [ICacheDependency $dependency = null])

- string $id: the key identifying the value to be cached
- mixed $value: the value to be cached
- integer $expire: the number of seconds in which the cached value will expire. 0 means never expire.
- ICacheDependency $dependency: dependency of the cached item. If the dependency changes, the item is labelled invalid.

setKeyPrefix (line 101)

- access: public

void setKeyPrefix (string $value)

- string $value: a unique prefix for the keys of cached values

setPrimaryCache (line 84)

- access: public
- see: TCache::getPrimaryCache()

void setPrimaryCache (boolean $value)

- boolean $value: whether this cache module is used as primary/system cache. Defaults to false.

setValue (line 209)

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.

- return: true if the value is successfully stored into cache, false otherwise
- access: protected
- abstract:

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

- string $key: the key identifying the value to be cached
- string $value: the value to be cached
- integer $expire: the number of seconds in which the cached value will expire. 0 means never expire.

Redefined in descendants as:

- TAPCCache::setValue() : Stores a value identified by a key in cache.
- TMemCache::setValue() : Stores a value identified by a key in cache.
- TSqliteCache::setValue() : Stores a value identified by a key in cache.

#### Inherited Methods

Inherited From TModule

> TModule::getID()
> TModule::init()
> TModule::setID()

Inherited From TApplicationComponent

> TApplicationComponent::getApplication()
> TApplicationComponent::getRequest()
> TApplicationComponent::getResponse()
> TApplicationComponent::getService()
> TApplicationComponent::getSession()
> TApplicationComponent::getUser()
> TApplicationComponent::publishAsset()
> TApplicationComponent::publishFilePath()

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

Documentation generated on Sun, 14 Jan 2007 21:41:20 -0500 by phpDocumentor 1.3.0RC4