W3cubDocs

/Yii 1.1

CCacheHttpSession

Package system.web
Inheritance class CCacheHttpSession » CHttpSession » CApplicationComponent » CComponent
Implements Countable, ArrayAccess, Traversable, IteratorAggregate, IApplicationComponent
Since 1.0
Source Code framework/web/CCacheHttpSession.php
CCacheHttpSession implements a session component using cache as storage medium.

The cache being used can be any cache application component implementing ICache interface. The ID of the cache application component is specified via cacheID, which defaults to 'cache'.

Beware, by definition cache storage are volatile, which means the data stored on them may be swapped out and get lost. Therefore, you must make sure the cache used by this component is NOT volatile. If you want to use CDbCache as storage medium, use CDbHttpSession is a better choice.

Public Properties

Property Type Description Defined By
autoStart boolean whether the session should be automatically started when the session application component is initialized, defaults to true. CHttpSession
behaviors array the behaviors that should be attached to this component. CApplicationComponent
cacheID string the ID of the cache application component. CCacheHttpSession
cookieMode string how to use cookie to store session ID. CHttpSession
cookieParams array the session cookie parameters. CHttpSession
count integer Returns the number of items in the session. CHttpSession
gCProbability float the probability (percentage) that the gc (garbage collection) process is started on every session initialization, defaults to 1 meaning 1% chance. CHttpSession
isInitialized boolean Checks if this application component has been initialized. CApplicationComponent
isStarted boolean whether the session has started CHttpSession
iterator CHttpSessionIterator Returns an iterator for traversing the session variables. CHttpSession
keys array the list of session variable names CHttpSession
savePath string the current session save path, defaults to {@link http://php. CHttpSession
sessionID string the current session ID CHttpSession
sessionName string the current session name CHttpSession
timeout integer the number of seconds after which data will be seen as 'garbage' and cleaned up, defaults to 1440 seconds. CHttpSession
useCustomStorage boolean Returns a value indicating whether to use custom session storage. CCacheHttpSession
useTransparentSessionID boolean whether transparent sid support is enabled or not, defaults to false. CHttpSession

Public Methods

Method Description Defined By
__call() Calls the named method which is not a class method. CComponent
__get() Returns a property value, an event handler list or a behavior based on its name. CComponent
__isset() Checks if a property value is null. CComponent
__set() Sets value of a component property. CComponent
__unset() Sets a component property to be null. CComponent
add() Adds a session variable. CHttpSession
asa() Returns the named behavior object. CComponent
attachBehavior() Attaches a behavior to this component. CComponent
attachBehaviors() Attaches a list of behaviors to the component. CComponent
attachEventHandler() Attaches an event handler to an event. CComponent
canGetProperty() Determines whether a property can be read. CComponent
canSetProperty() Determines whether a property can be set. CComponent
clear() Removes all session variables CHttpSession
close() Ends the current session and store session data. CHttpSession
closeSession() Session close handler. CHttpSession
contains() CHttpSession
count() Returns the number of items in the session. CHttpSession
destroy() Frees all session variables and destroys all data registered to a session. CHttpSession
destroySession() Session destroy handler. CCacheHttpSession
detachBehavior() Detaches a behavior from the component. CComponent
detachBehaviors() Detaches all behaviors from the component. CComponent
detachEventHandler() Detaches an existing event handler. CComponent
disableBehavior() Disables an attached behavior. CComponent
disableBehaviors() Disables all behaviors attached to this component. CComponent
enableBehavior() Enables an attached behavior. CComponent
enableBehaviors() Enables all behaviors attached to this component. CComponent
evaluateExpression() Evaluates a PHP expression or callback under the context of this component. CComponent
gcSession() Session GC (garbage collection) handler. CHttpSession
get() Returns the session variable value with the session variable name. CHttpSession
getCookieMode() Returns how to use cookie to store session ID. Defaults to 'Allow'. CHttpSession
getCookieParams() Returns the session cookie parameters. CHttpSession
getCount() Returns the number of items in the session. CHttpSession
getEventHandlers() Returns the list of attached event handlers for an event. CComponent
getGCProbability() Returns the probability (percentage) that the gc (garbage collection) process is started on every session initialization, defaults to 1 meaning 1% chance. CHttpSession
getIsInitialized() Checks if this application component has been initialized. CApplicationComponent
getIsStarted() Checks whether the session has started CHttpSession
getIterator() Returns an iterator for traversing the session variables. CHttpSession
getKeys() Returns the list of session variable names CHttpSession
getSavePath() Returns the current session save path, defaults to http://php.net/session.save_path. CHttpSession
getSessionID() Returns the current session ID CHttpSession
getSessionName() Returns the current session name CHttpSession
getTimeout() Returns the number of seconds after which data will be seen as 'garbage' and cleaned up, defaults to 1440 seconds. CHttpSession
getUseCustomStorage() Returns a value indicating whether to use custom session storage. CCacheHttpSession
getUseTransparentSessionID() Returns whether transparent sid support is enabled or not, defaults to false. CHttpSession
hasEvent() Determines whether an event is defined. CComponent
hasEventHandler() Checks whether the named event has attached handlers. CComponent
hasProperty() Determines whether a property is defined. CComponent
init() Initializes the application component. CCacheHttpSession
itemAt() Returns the session variable value with the session variable name. CHttpSession
offsetExists() This method is required by the interface ArrayAccess. CHttpSession
offsetGet() This method is required by the interface ArrayAccess. CHttpSession
offsetSet() This method is required by the interface ArrayAccess. CHttpSession
offsetUnset() This method is required by the interface ArrayAccess. CHttpSession
open() Starts the session if it has not started yet. CHttpSession
openSession() Session open handler. CHttpSession
raiseEvent() Raises an event. CComponent
readSession() Session read handler. CCacheHttpSession
regenerateID() Updates the current session id with a newly generated one . CHttpSession
remove() Removes a session variable. CHttpSession
setCookieMode() Sets how to use cookie to store session ID. Valid values include 'none', 'allow' and 'only'. CHttpSession
setCookieParams() Sets the session cookie parameters. CHttpSession
setGCProbability() Sets the probability (percentage) that the gc (garbage collection) process is started on every session initialization. CHttpSession
setSavePath() Sets the current session save path CHttpSession
setSessionID() Sets the session ID for the current session CHttpSession
setSessionName() Sets the session name for the current session, must be an alphanumeric string, defaults to PHPSESSID CHttpSession
setTimeout() Sets the number of seconds after which data will be seen as 'garbage' and cleaned up CHttpSession
setUseTransparentSessionID() Sets whether transparent sid support is enabled or not. CHttpSession
toArray() CHttpSession
writeSession() Session write handler. CCacheHttpSession

Protected Methods

Method Description Defined By
calculateKey() Generates a unique key used for storing session data in cache. CCacheHttpSession

Property Details

cacheID property

public string $cacheID;

the ID of the cache application component. Defaults to 'cache' (the primary cache application component.)

useCustomStorage property read-only

public boolean getUseCustomStorage()

Returns a value indicating whether to use custom session storage. This method overrides the parent implementation and always returns true.

Method Details

calculateKey() method

protected string calculateKey(string $id)
$id string session variable name
{return} string a safe cache key associated with the session variable name
Source Code: framework/web/CCacheHttpSession.php#114 (show)
protected function calculateKey($id)
{
    return 
self::CACHE_KEY_PREFIX.$id;
}

Generates a unique key used for storing session data in cache.

destroySession() method

public boolean destroySession(string $id)
$id string session ID
{return} boolean true if no error happens during deletion
Source Code: framework/web/CCacheHttpSession.php#103 (show)
public function destroySession($id)
{
    
$this->_cache->delete($this->calculateKey($id));
    return 
true;
}

Session destroy handler. Do not call this method directly.

Since 1.1.18 release, this method always returns true. Please refer to the following issue for more details: https://github.com/yiisoft/yii/issues/4020

getUseCustomStorage() method

public boolean getUseCustomStorage()
{return} boolean whether to use custom storage.
Source Code: framework/web/CCacheHttpSession.php#63 (show)
public function getUseCustomStorage()
{
    return 
true;
}

Returns a value indicating whether to use custom session storage. This method overrides the parent implementation and always returns true.

init() method

public void init()
Source Code: framework/web/CCacheHttpSession.php#49 (show)
public function init()
{
    
$this->_cache=Yii::app()->getComponent($this->cacheID);
    if(!(
$this->_cache instanceof ICache))
        throw new 
CException(Yii::t('yii','CCacheHttpSession.cacheID is invalid. Please make sure "{id}" refers to a valid cache application component.',
            array(
'{id}'=>$this->cacheID)));
    
parent::init();
}

Initializes the application component. This method overrides the parent implementation by checking if cache is available.

readSession() method

public string readSession(string $id)
$id string session ID
{return} string the session data
Source Code: framework/web/CCacheHttpSession.php#74 (show)
public function readSession($id)
{
    
$data=$this->_cache->get($this->calculateKey($id));
    return 
$data===false?'':$data;
}

Session read handler. Do not call this method directly.

writeSession() method

public boolean writeSession(string $id, string $data)
$id string session ID
$data string session data
{return} boolean whether session write is successful
Source Code: framework/web/CCacheHttpSession.php#87 (show)
public function writeSession($id,$data)
{
    return 
$this->_cache->set($this->calculateKey($id),$data,$this->getTimeout());
}

Session write handler. Do not call this method directly.

© 2008–2017 by Yii Software LLC
Licensed under the three clause BSD license.
http://www.yiiframework.com/doc/api/1.1/CCacheHttpSession