PRADO Component Framework for PHP 5
  • Home
  • About
  • Testimonials
  • Demos
  • Download
  • Documentation
  • Forum
  • Development
  • Tutorials
  • Class Docs
  • API Manual
  • Wiki

Packages

  • None
  • System
    • Caching
    • Collections
    • Data
      • ActiveRecord
        • Relations
        • Scaffold
          • InputBuilder
      • Commom
        • Sqlite
      • Common
        • Mssql
        • Mysql
        • Oracle
        • Pgsql
        • Sqlite
      • DataGateway
      • SqlMap
        • Configuration
        • Statements
    • Exceptions
    • I18N
    • IO
    • Security
    • Util
    • Web
      • Javascripts
      • Services
      • UI
        • ActiveControls
        • WebControls
    • Xml
  • Wsat
    • pages
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo

Class TCache

TCache class

TCache is the base class for cache classes with different cache storage implementation.

TCache implements the interface ICache with the following methods,

  • TCache::get() : retrieve the value with a key (if any) from cache
  • TCache::set() : store the value with a key into cache
  • TCache::add() : store the value only if cache does not have this key
  • TCache::delete() : delete the value with the specified key from cache
  • TCache::flush() : delete all values from cache

Each value is associated with an expiration time. The TCache::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:

  • TCache::getValue()
  • TCache::setValue()
  • TCache::addValue()
  • TCache::deleteValue()

and optionally TCache::flush()

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

TComponent
Extended by TApplicationComponent
Extended by TModule implements IModule
Extended by TCache implements ICache, ArrayAccess

Direct known subclasses

TAPCCache, TDbCache, TEACache, TMemCache, TSqliteCache, TXCache
Abstract
Package: System\Caching
Copyright: Copyright © 2005-2014 PradoSoft
License: http://www.pradosoft.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 3.0
Located at Caching/TCache.php
Methods summary
public
# 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.

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

Parameters

$config
TXmlElement
the module configuration

Overrides

TModule::init()
public boolean
# getPrimaryCache( )

Returns

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.
public
# setPrimaryCache( boolean $value )

Parameters

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

See

TCache::getPrimaryCache()
public string
# getKeyPrefix( )

Returns

string
a unique prefix for the keys of cached values. If it is not explicitly set, it will take the value of TApplication::getUniqueID().
public
# setKeyPrefix( string $value )

Parameters

$value
string
a unique prefix for the keys of cached values
protected sring
# generateUniqueKey( string $key )

Parameters

$key
string
a key identifying a value to be cached

Returns

sring
a key generated from the provided key which ensures the uniqueness across applications
public mixed
# get( string $id )

Retrieves a value from cache with a specified key.

Retrieves a value from cache with a specified key.

Parameters

$id
string
a key identifying the cached value

Returns

mixed
the value stored in cache, false if the value is not in the cache or expired.

Implementation of

ICache::get()
public boolean
# set( string $id, mixed $value, integer $expire = 0, ICacheDependency $dependency = null )

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.

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.

Parameters

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

Returns

boolean
true if the value is successfully stored into cache, false otherwise

Implementation of

ICache::set()
public boolean
# add( string $id, mixed $value, integer $expire = 0, ICacheDependency $dependency = null )

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.

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.

Parameters

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

Returns

boolean
true if the value is successfully stored into cache, false otherwise

Implementation of

ICache::add()
public boolean
# delete( string $id )

Deletes a value with the specified key from cache

Deletes a value with the specified key from cache

Parameters

$id
string
the key of the value to be deleted

Returns

boolean
if no error happens during deletion

Implementation of

ICache::delete()
public
# 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.

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.

Throws

TNotSupportedException
if this method is not overridden by child classes

Implementation of

ICache::flush()
abstract protected 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 TCache::get() already. So only the implementation of data retrieval is needed.

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

Parameters

$key
string
a unique key identifying the cached value

Returns

string
the value stored in cache, false if the value is not in the cache or expired.
abstract protected 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 TCache::set() already. So only the implementation of data storage is needed.

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

Parameters

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

Returns

boolean
true if the value is successfully stored into cache, false otherwise
abstract protected 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 TCache::add() already. So only the implementation of data storage is needed.

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

Parameters

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

Returns

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

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.

Parameters

$key
string
the key of the value to be deleted

Returns

boolean
if no error happens during deletion
public boolean
# offsetExists( string $id )

Returns whether there is a cache entry with a specified key. This method is required by the interface ArrayAccess.

Returns whether there is a cache entry with a specified key. This method is required by the interface ArrayAccess.

Parameters

$id
string
a key identifying the cached value

Returns

boolean

Implementation of

ArrayAccess::offsetExists()
public mixed
# offsetGet( string $id )

Retrieves the value from cache with a specified key. This method is required by the interface ArrayAccess.

Retrieves the value from cache with a specified key. This method is required by the interface ArrayAccess.

Parameters

$id
string
a key identifying the cached value

Returns

mixed
the value stored in cache, false if the value is not in the cache or expired.

Implementation of

ArrayAccess::offsetGet()
public
# offsetSet( string $id, mixed $value )

Stores the value identified by a key into cache. 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.

Stores the value identified by a key into cache. 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.

Parameters

$id
string
the key identifying the value to be cached
$value
mixed
the value to be cached

Implementation of

ArrayAccess::offsetSet()
public boolean
# offsetUnset( string $id )

Deletes the value with the specified key from cache This method is required by the interface ArrayAccess.

Deletes the value with the specified key from cache This method is required by the interface ArrayAccess.

Parameters

$id
string
the key of the value to be deleted

Returns

boolean
if no error happens during deletion

Implementation of

ArrayAccess::offsetUnset()
Methods inherited from TModule
getID(), setID()
Methods inherited from TApplicationComponent
getApplication(), getRequest(), getResponse(), getService(), getSession(), getUser(), publishAsset(), publishFilePath()
Methods inherited from TComponent
__call(), __construct(), __destruct(), __get(), __isset(), __set(), __sleep(), __unset(), __wakeup(), addParsedObject(), asa(), attachBehavior(), attachBehaviors(), attachClassBehavior(), attachEventHandler(), canGetProperty(), canSetProperty(), clearBehaviors(), createdOnTemplate(), detachBehavior(), detachBehaviors(), detachClassBehavior(), detachEventHandler(), disableBehavior(), disableBehaviors(), enableBehavior(), enableBehaviors(), evaluateExpression(), evaluateStatements(), fxAttachClassBehavior(), fxDetachClassBehavior(), getAutoGlobalListen(), getBehaviorsEnabled(), getClassHierarchy(), getEventHandlers(), getListeningToGlobalEvents(), getSubProperty(), hasEvent(), hasEventHandler(), hasProperty(), isa(), listen(), raiseEvent(), setSubProperty(), unlisten()
Constants inherited from TComponent
GLOBAL_RAISE_EVENT_LISTENER
Terms of Service | Contact Us
PRADO v3.2.4 API Manual API documentation generated by ApiGen 2.8.0
Copyright © 2006-2014 by the PRADO Group.
Powered by PRADO