system system.base system.caching system.caching.dependencies system.collections system.console system.db system.db.ar system.db.schema system.db.schema.cubrid system.db.schema.mssql system.db.schema.mysql system.db.schema.oci system.db.schema.pgsql system.db.schema.sqlite system.gii system.i18n system.i18n.gettext system.logging system.test system.utils system.validators system.web system.web.actions system.web.auth system.web.filters system.web.form system.web.helpers system.web.renderers system.web.services system.web.widgets system.web.widgets.captcha system.web.widgets.pagers zii.behaviors zii.widgets zii.widgets.grid zii.widgets.jui

CCacheHttpSession

system.web
继承 class CCacheHttpSession » CHttpSession » CApplicationComponent » CComponent
实现 Countable, ArrayAccess, Traversable, IteratorAggregate, IApplicationComponent
可用自 1.0
源码 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.

公共属性

隐藏继承的属性

属性类型描述被定义在
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

公共方法

隐藏继承的方法

方法描述被定义在
__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
setCacheLimiter() Set cache limiter 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

受保护的方法

隐藏继承的方法

方法描述被定义在
calculateKey() Generates a unique key used for storing session data in cache. CCacheHttpSession
freeze() If session is started we cannot edit session ini settings. CHttpSession
unfreeze() Start session and restore data from temporary variable CHttpSession

属性详情

cacheID 属性
public string $cacheID;

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

useCustomStorage 属性 只读
public boolean getUseCustomStorage()

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

方法详情

calculateKey() 方法
protected string calculateKey(string $id)
$id string session variable name
{return} string a safe cache key associated with the session variable name
源码: framework/web/CCacheHttpSession.php#114 (显示)
protected function calculateKey($id)
{
    return 
self::CACHE_KEY_PREFIX.$id;
}

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

destroySession() 方法
public boolean destroySession(string $id)
$id string session ID
{return} boolean true if no error happens during deletion
源码: framework/web/CCacheHttpSession.php#103 (显示)
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() 方法
public boolean getUseCustomStorage()
{return} boolean whether to use custom storage.
源码: framework/web/CCacheHttpSession.php#63 (显示)
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() 方法
public void init()
源码: framework/web/CCacheHttpSession.php#49 (显示)
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() 方法
public string readSession(string $id)
$id string session ID
{return} string the session data
源码: framework/web/CCacheHttpSession.php#74 (显示)
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() 方法
public boolean writeSession(string $id, string $data)
$id string session ID
$data string session data
{return} boolean whether session write is successful
源码: framework/web/CCacheHttpSession.php#87 (显示)
public function writeSession($id,$data)
{
    return 
$this->_cache->set($this->calculateKey($id),$data,$this->getTimeout());
}

Session write handler. Do not call this method directly.