Class TCacheHttpSession
TCacheHttpSession class
TCacheHttpSession provides access for storing session data using a cache module (e.g. TMemCache, TDbCache). To specify the cache module for data storage, set the CacheModuleID property which should refer to a valid cache module configured in the application configuration. The following example shows how we configure TCacheHttpSession: - <modules>
- <module id="cache" class="System.Caching.TMemCache" Host="localhost" Port="11211" />
- <module id="session" class="System.Web.TCacheHttpSession"
- CacheModuleID="cache" SessionName="SSID"
- CookieMode="Allow" AutoStart="true" GCProbability="1"
- UseTransparentSessionID="true" TimeOut="3600" />
- </modules>
Beware, by definition cache storage are volatile, which means the data stored on them may be swapped out and get lost. This may not be the case for certain cache storage, such as database. So make sure you manage your cache properly to avoid loss of session data.
Method Summary |
protected
string
|
|
ICache
|
|
string
|
|
string
|
|
void
|
Initializes the module.
|
void
|
|
void
|
|
boolean
|
Session destroy handler.
|
string
|
Session read handler.
|
boolean
|
_write
( string $id, string $data)
Session write handler.
|
Methods Inherited From THttpSession |
THttpSession::add(), THttpSession::clear(), THttpSession::close(), THttpSession::contains(), THttpSession::count(), THttpSession::destroy(), THttpSession::getAutoStart(), THttpSession::getCookie(), THttpSession::getCookieMode(), THttpSession::getCount(), THttpSession::getGCProbability(), THttpSession::getID(), THttpSession::getIsStarted(), THttpSession::getIterator(), THttpSession::getKeys(), THttpSession::getSavePath(), THttpSession::getSessionID(), THttpSession::getSessionName(), THttpSession::getTimeout(), THttpSession::getUseCustomStorage(), THttpSession::getUseTransparentSessionID(), THttpSession::init(), THttpSession::itemAt(), THttpSession::offsetExists(), THttpSession::offsetGet(), THttpSession::offsetSet(), THttpSession::offsetUnset(), THttpSession::open(), THttpSession::remove(), THttpSession::setAutoStart(), THttpSession::setCookieMode(), THttpSession::setGCProbability(), THttpSession::setID(), THttpSession::setSavePath(), THttpSession::setSessionID(), THttpSession::setSessionName(), THttpSession::setTimeout(), THttpSession::setUseCustomStorage(), THttpSession::setUseTransparentSessionID(), THttpSession::toArray(), THttpSession::_close(), THttpSession::_destroy(), THttpSession::_gc(), THttpSession::_open(), THttpSession::_read(), THttpSession::_write()
|
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 $id ) |
Input |
string | $id | session variable name |
Output |
string
| a safe cache key associated with the session variable name |
Exception |
|
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 |
|
getKeyPrefix
public string getKeyPrefix |
() |
Output |
string
| prefix of session variable name to avoid conflict with other cache data. Defaults to 'session'. |
Exception |
|
init
Initializes the module.
This method is required by IModule. It reads the CacheModule property.
Input |
TXmlElement | $config | module configuration |
Output |
Exception |
|
setCacheModuleID
public void setCacheModuleID |
(string $value ) |
Input |
string | $value | the ID of the cache module. |
Output |
Exception |
|
setKeyPrefix
public void setKeyPrefix |
(string $value ) |
Input |
string | $value | prefix of session variable name to avoid conflict with other cache data |
Output |
Exception |
|
_destroy
public boolean _destroy |
(string $id ) |
Session destroy handler.
This method should be overriden if UseCustomStorage is set true.
Input |
string | $id | session ID |
Output |
boolean
| whether session is destroyed successfully |
Exception |
|
_read
public string _read |
(string $id ) |
Session read handler.
Input |
string | $id | session ID |
Output |
string
| the session data |
Exception |
|
_write
public boolean _write |
(string $id , string $data ) |
Session write handler.
Input |
string | $id | session ID |
string | $data | session data |
Output |
boolean
| whether session write is successful |
Exception |
|
|