Class TCachePageStatePersister

Description

Implements interfaces:

TCachePageStatePersister class

TCachePageStatePersister implements a page state persistent method based on cache. Page state are stored in cache (e.g. memcache, DB cache, etc.), and only a small token is passed to the client side to identify the state. This greatly reduces the size of the page state that needs to be transmitted between the server and the client. Of course, this is at the cost of using server side resource.

A cache module has to be loaded in order to use TCachePageStatePersister. By default, TCachePageStatePersister will use the primary cache module. A non-primary cache module can be used by setting CacheModuleID. Any cache module, as long as it implements the interface ICache, may be used. For example, one can use TDbCache, TMemCache, TAPCCache, etc.

TCachePageStatePersister uses CacheTimeout to limit the data that stores in cache.

Since server resource is often limited, be cautious if you plan to use TCachePageStatePersister for high-traffic Web pages. You may consider using a small CacheTimeout.

There are a couple of ways to use TCachePageStatePersister. One can override the page's TPage::getStatePersister() method and create a TCachePageStatePersister instance there. Or one can configure the pages to use TCachePageStatePersister in page configurations as follows,

  1. <pages StatePersisterClass="System.Web.UI.TCachePageStatePersister"
  2. StatePersister.CacheModuleID="mycache"
  3. StatePersister.CacheTimeout="3600" />
Note in the above, we use StatePersister.CacheModuleID to configure the cache module ID for the TCachePageStatePersister instance.

The above configuration will affect the pages under the directory containing this configuration and all its subdirectories. To configure individual pages to use TCachePageStatePersister, use

  1. <pages>
  2. <page id="PageID" StatePersisterClass="System.Web.UI.TCachePageStatePersister" />
  3. </pages>

  • since: 3.1.1
  • version: $Id: TCachePageStatePersister.php 2228 2007-09-17 18:18:17Z xue $
  • author: Qiang Xue <qiang.xue@gmail.com>

Located in /Web/UI/TCachePageStatePersister.php (line 61)

TComponent
   |
   --TCachePageStatePersister
Method Summary
string calculateKey (string $timestamp)
string getCacheModuleID ()
integer getCacheTimeout ()
string getKeyPrefix ()
void getPage (TPage 0)
mixed load ()
void save (mixed $state)
void setCacheModuleID (string $value)
void setCacheTimeout (integer $value)
void setKeyPrefix (string $value)
void setPage (TPage $page)
Methods
calculateKey (line 164)
  • return: a key that is unique per user request
  • access: protected
string calculateKey (string $timestamp)
  • string $timestamp: micro timestamp when saving state occurs
getCache (line 104)
  • return: the cache module being used for data storage
  • access: public
ICache getCache ()
getCacheModuleID (line 88)
  • return: the ID of the cache module.
  • access: public
string getCacheModuleID ()
getCacheTimeout (line 127)
  • return: the number of seconds in which the cached state will expire. Defaults to 1800.
  • access: public
integer getCacheTimeout ()
getKeyPrefix (line 147)
  • return: prefix of cache variable name to avoid conflict with other cache data. Defaults to 'statepersister'.
  • access: public
string getKeyPrefix ()
getPage (line 72)
  • access: public
void getPage (TPage 0)
  • TPage 0: the page that this persister works for
load (line 190)

Loads page state from cache.

  • return: the restored state
  • access: public
  • throws: THttpException if page state is corrupted
mixed load ()
save (line 176)

Saves state in cache.

  • access: public
void save (mixed $state)
  • mixed $state: state to be stored
setCacheModuleID (line 96)
  • access: public
void setCacheModuleID (string $value)
  • string $value: the ID of the cache module. If not set, the primary cache module will be used.
setCacheTimeout (line 136)
  • access: public
  • throws: TInvalidDataValueException if the number is smaller than 0.
void setCacheTimeout (integer $value)
  • integer $value: the number of seconds in which the cached state will expire. 0 means never expire.
setKeyPrefix (line 155)
  • access: public
void setKeyPrefix (string $value)
  • string $value: prefix of cache variable name to avoid conflict with other cache data
setPage (line 80)
  • access: public
void setPage (TPage $page)
  • TPage $page: the page that this persister works for.

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

Documentation generated on Mon, 21 Apr 2008 11:32:11 -0400 by phpDocumentor 1.3.0RC4