- Home
- About
- Testimonials
- Demos
- Download
- Documentation
- Blogs
- Forum
- Support

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:
IBroadcastEventReceiver
IButtonControl
INamingContainer
IPageStatePersister
IPostBackDataHandler
IPostBackEventHandler
ISurroundable
ITemplate
ITheme
IValidatable
IValidator
TBroadcastEventParameter
TCachePageStatePersister
TClientScriptManager
TClientSideOptions
TCommandEventParameter
TCompositeControl
TCompositeLiteral
TControl
TControlAdapter
TControlCollection
TEmptyControlCollection
TForm
THead
THtmlWriter
TPage
TPageStateFormatter
TPageStatePersister
TSessionPageStatePersister
TTemplate
TTemplateControl
TTemplateManager
TTextProcessor
TTheme
TThemeManager

Keyword

# Class TCachePageStatePersister

    TComponent
       |
       --TCachePageStatePersister

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,

       <pages StatePersisterClass="System.Web.UI.TCachePageStatePersister"
              StatePersister.CacheModuleID="mycache"
              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

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

Since: 3.1.1
Author: Qiang Xue <qiang.xue@gmail.com>

Method Summary
protected string | calculateKey ( string $timestamp)
ICache | getCache ()
string | getCacheModuleID ()
integer | getCacheTimeout ()
string | getKeyPrefix ()
void | getPage ( TPage 0)
mixed | load () Loads page state from cache.
void | save ( mixed $state) Saves state in cache.
void | setCacheModuleID ( string $value)
void | setCacheTimeout ( integer $value)
void | setKeyPrefix ( string $value)
void | setPage ( TPage $page)

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

## calculateKey

protected string calculateKey | (string $timestamp )

Input
string | $timestamp | micro timestamp when saving state occurs
Output
string | a key that is unique per user request
Exception

## getCache

public ICache getCache | ()

Output
ICache | the cache module being used for data storage
Exception

## getCacheModuleID

public string getCacheModuleID | ()

Output
string | the ID of the cache module.
Exception

## getCacheTimeout

public integer getCacheTimeout | ()

Output
integer | the number of seconds in which the cached state will expire. Defaults to 1800.
Exception

## getKeyPrefix

public string getKeyPrefix | ()

Output
string | prefix of cache variable name to avoid conflict with other cache data. Defaults to 'statepersister'.
Exception

## getPage

public void getPage | (TPage 0 )

Input
TPage | 0 | the page that this persister works for
Output
Exception

## load

public mixed load | ()

Loads page state from cache.

Output
mixed | the restored state
Exception
throws | THttpException if page state is corrupted

## save

public void save | (mixed $state )

Saves state in cache.

Input
mixed | $state | state to be stored
Output
Exception

## setCacheModuleID

public void setCacheModuleID | (string $value )

Input
string | $value | the ID of the cache module. If not set, the primary cache module will be used.
Output
Exception

## setCacheTimeout

public void setCacheTimeout | (integer $value )

Input
integer | $value | the number of seconds in which the cached state will expire. 0 means never expire.
Output
Exception
throws | TInvalidDataValueException if the number is smaller than 0.

## setKeyPrefix

public void setKeyPrefix | (string $value )

Input
string | $value | prefix of cache variable name to avoid conflict with other cache data
Output
Exception

## setPage

public void setPage | (TPage $page )

Input
TPage | $page | the page that this persister works for.
Output
Exception