## 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

Since version 3.1.2, TCache implements the ArrayAccess interface such that the cache acts as an array.

- abstract:
- since: 3.0
- version: $Id: TCache.php 2362 2008-01-10 04:59:06Z xue $
- author: Qiang Xue <qiang.xue@gmail.com>

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

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

Direct descendents

Class | Description
--- | ---
TAPCCache | TAPCCache class
TDbCache | TDbCache class
TMemCache | TMemCache class
TSqliteCache | TSqliteCache class
TXCache | TXCache 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 offsetExists (string $id)
void offsetGet (mixed $id)
void offsetSet (mixed $id, mixed $value)
void offsetUnset (mixed $id)
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 162)

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 labeled invalid.

addValue (line 226)

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.
- TDbCache::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.
- TXCache::addValue() : Stores a value identified by a key into cache if the cache does not contain this key.

delete (line 173)

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

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.
- TDbCache::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.
- TXCache::deleteValue() : Deletes a value with the specified key from cache This is the implementation of the method declared in the parent class.

flush (line 184)

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 overridden by child classes

void flush ()

Redefined in descendants as:

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

generateUniqueKey (line 113)

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

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

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

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

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.
- TDbCache::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.
- TXCache::getValue() : Retrieves a value from cache with a specified key.

init (line 60)

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.
- TDbCache::init() : Initializes this module.
- TMemCache::init() : Initializes this module.
- TSqliteCache::init() : Initializes this module.
- TXCache::init() : Initializes this module.

offsetExists (line 242)

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

This method is required by the interface ArrayAccess.

- access: public

boolean offsetExists (string $id)

- string $id: a key identifying the cached value

offsetGet (line 253)

- access: public

void offsetGet (mixed $id)
offsetSet (line 266)

- access: public

void offsetSet (mixed $id, mixed $value)
offsetUnset (line 277)

- access: public

void offsetUnset (mixed $id)
set (line 147)

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 labeled invalid.

setKeyPrefix (line 104)

- access: public

void setKeyPrefix (string $value)

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

setPrimaryCache (line 87)

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

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.
- TDbCache::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.
- TXCache::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 Mon, 21 Apr 2008 11:32:01 -0400 by phpDocumentor 1.3.0RC4