CCacheHttpSession

优质
小牛编辑
121浏览
2023-12-01
所有包 | 属性 | 方法
system.web
继承class CCacheHttpSession » CHttpSession » CApplicationComponent » CComponent
实现Countable, ArrayAccess, Traversable, IteratorAggregate, IApplicationComponent
源自1.0
版本$Id: CCacheHttpSession.php 3426 2011-10-25 00:01:09Z alexander.makarow $
源码framework/web/CCacheHttpSession.php
CCacheHttpSession实现了使用缓存作为存储介质的会话组件。

只要是实现了ICache接口的应用组件都可以作为缓存。 这个缓存ID是通过cacheID来指定的,默认值是‘cache’。

要注意的是,缓存介质是很容易改变的, 那就意味着存储在上面的数据会被刷掉。因此,你必须确定这个组件使用的存储是容易改变。 如果你想要用CDbCache作为存储介质,CDbHttpSession 会是一个更好的选择。

公共属性

隐藏继承属性

属性类型描述定义在
autoStartbooleanwhether the session should be automatically started when the session application component is initialized, defaults to true.CHttpSession
behaviorsarray这个应用组件附加的行为。 这此行为将在应用组件调用init时附加在应用组件上。 请参照CModel::behaviors如何指定此属性值。CApplicationComponent
cacheIDstring缓存应用组件ID。默认是‘cache’(原始缓存应用组件。)CCacheHttpSession
cookieModestringhow to use cookie to store session ID.CHttpSession
cookieParamsarraythe session cookie parameters.CHttpSession
countintegerReturns the number of items in the session.CHttpSession
gCProbabilityintegerthe probability (percentage) that the gc (garbage collection) process is started on every session initialization, defaults to 1 meaning 1% chance.CHttpSession
isInitializedboolean检查应用组件是否已经初始化。CApplicationComponent
isStartedbooleanwhether the session has startedCHttpSession
iteratorCHttpSessionIteratorReturns an iterator for traversing the session variables.CHttpSession
keysarraythe list of session variable namesCHttpSession
savePathstringthe current session save path, defaults to '/tmp'.CHttpSession
sessionIDstringthe current session IDCHttpSession
sessionNamestringthe current session nameCHttpSession
timeoutintegerthe number of seconds after which data will be seen as 'garbage' and cleaned up, defaults to 1440 seconds.CHttpSession
useCustomStorageboolean返回一个值,指示是否使用自定义的会话存储。CCacheHttpSession
useTransparentSessionIDbooleanwhether transparent sid support is enabled or not, defaults to false.CHttpSession

公共方法

隐藏继承方法

方法描述定义在
__call()如果类中没有调的方法名,则调用这个方法。CComponent
__get()返回一个属性值、一个事件处理程序列表或一个行为名称。CComponent
__isset()检查一个属性是否为null。CComponent
__set()设置一个组件的属性值。CComponent
__unset()设置一个组件的属性为null。CComponent
add()Adds a session variable.CHttpSession
asa()返回这个名字的行为对象。CComponent
attachBehavior()附加一个行为到组件。CComponent
attachBehaviors()附加一个行为列表到组件。CComponent
attachEventHandler()为事件附加一个事件处理程序。CComponent
canGetProperty()确定属性是否可读。CComponent
canSetProperty()确定属性是否可写。CComponent
clear()Removes all session variablesCHttpSession
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()会话销毁处理程序。CCacheHttpSession
detachBehavior()从组件中分离一个行为。CComponent
detachBehaviors()从组件中分离所有行为。CComponent
detachEventHandler()分离一个存在的事件处理程序。CComponent
disableBehavior()禁用一个附加行为。CComponent
disableBehaviors()禁用组件附加的所有行为。CComponent
enableBehavior()启用一个附加行为。CComponent
enableBehaviors()启用组件附加的所有行为。CComponent
evaluateExpression()计算一个PHP表达式,或根据组件上下文执行回调。CComponent
gcSession()Session GC (garbage collection) handler.CHttpSession
get()Returns the session variable value with the session variable name.CHttpSession
getCookieMode()返回how to use cookie to store session ID. Defaults to 'Allow'.CHttpSession
getCookieParams()返回the session cookie parameters.CHttpSession
getCount()Returns the number of items in the session.CHttpSession
getEventHandlers()返回一个事件的附加处理程序列表。CComponent
getGCProbability()返回the probability (percentage) that the gc (garbage collection) process is started on every session initialization, defaults to 1 meaning 1% chance.CHttpSession
getIsInitialized()检查应用组件是否已经初始化。CApplicationComponent
getIsStarted()检查whether the session has startedCHttpSession
getIterator()Returns an iterator for traversing the session variables.CHttpSession
getKeys()返回the list of session variable namesCHttpSession
getSavePath()返回the current session save path, defaults to '/tmp'.CHttpSession
getSessionID()返回the current session IDCHttpSession
getSessionName()返回the current session nameCHttpSession
getTimeout()返回the number of seconds after which data will be seen as 'garbage' and cleaned up, defaults to 1440 seconds.CHttpSession
getUseCustomStorage()返回一个值,指示是否使用自定义的会话存储。CCacheHttpSession
getUseTransparentSessionID()返回whether transparent sid support is enabled or not, defaults to false.CHttpSession
hasEvent()确定一个事件是否定义。CComponent
hasEventHandler()检查事件是否有附加的处理程序。CComponent
hasProperty()确定属性是否被定义。CComponent
init()初始化这个应用组件。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()发起一个事件。CComponent
readSession()会话读取处理程序。CCacheHttpSession
regenerateID()Updates the current session id with a newly generated one .CHttpSession
remove()Removes a session variable.CHttpSession
setCookieMode()设置how to use cookie to store session ID. Valid values include 'none', 'allow' and 'only'.CHttpSession
setCookieParams()Sets the session cookie parameters.CHttpSession
setGCProbability()设置the probability (percentage) that the gc (garbage collection) process is started on every session initialization.CHttpSession
setSavePath()设置the current session save pathCHttpSession
setSessionID()设置the session ID for the current sessionCHttpSession
setSessionName()设置the session name for the current session, must be an alphanumeric string, defaults to PHPSESSIDCHttpSession
setTimeout()设置the number of seconds after which data will be seen as 'garbage' and cleaned upCHttpSession
setUseTransparentSessionID()设置whether transparent sid support is enabled or not.CHttpSession
toArray()CHttpSession
writeSession()会话写入处理程序。CCacheHttpSession

受保护方法

隐藏继承方法

方法描述定义在
calculateKey()为将要存储的会员数据生成一个唯一的键名。CCacheHttpSession

属性详细

cacheID 属性 public string $cacheID;

缓存应用组件ID。默认是‘cache’(原始缓存应用组件。)

useCustomStorage 属性 只读 public boolean getUseCustomStorage()

返回一个值,指示是否使用自定义的会话存储。 这个方法是覆盖了父类方法,总是返回true。

方法详细

calculateKey() 方法
protected string calculateKey(string $id)
$idstring会话变量名字
{return}string安全的缓存键值和会话变量名字
源码: framework/web/CCacheHttpSession.php#109 (显示) protectedfunctioncalculateKey($id)
{
returnself::CACHE_KEY_PREFIX.$id;
}

为将要存储的会员数据生成一个唯一的键名。

destroySession() 方法
public boolean destroySession(string $id)
$idstring会话ID
{return}boolean会话是否被成功销毁
源码: framework/web/CCacheHttpSession.php#99 (显示) publicfunctiondestroySession($id)
{
return$this->_cache->delete($this->calculateKey($id));
}

会话销毁处理程序。 不要直接调用这个方法。

getUseCustomStorage() 方法
public boolean getUseCustomStorage()
{return}boolean是否使用常规存储。
源码: framework/web/CCacheHttpSession.php#64 (显示) publicfunctiongetUseCustomStorage()
{
returntrue;
}

返回一个值,指示是否使用自定义的会话存储。 这个方法是覆盖了父类方法,总是返回true。

init() 方法
public void init()
源码: framework/web/CCacheHttpSession.php#50 (显示) publicfunctioninit()
{
$this->_cache=Yii::app()->getComponent($this->cacheID);
if(!($this->_cacheinstanceofICache))
thrownewCException(Yii::t('yii','CCacheHttpSession.cacheIDisinvalid.Pleasemakesure"{id}"referstoavalidcacheapplicationcomponent.',
array('{id}'=>$this->cacheID)));
parent::init();
}

初始化这个应用组件。 这个方法覆盖了父类方法,主要是检查缓存是否可用。

readSession() 方法
public string readSession(string $id)
$idstring会话ID
{return}stringthe 会话数据
源码: framework/web/CCacheHttpSession.php#75 (显示) publicfunctionreadSession($id)
{
$data=$this->_cache->get($this->calculateKey($id));
return$data===false?'':$data;
}

会话读取处理程序。 不要直接调用这个方法。

writeSession() 方法
public boolean writeSession(string $id, string $data)
$idstring会话ID
$datastring会话数据
{return}boolean是否成功写入了会话数据
源码: framework/web/CCacheHttpSession.php#88 (显示) publicfunctionwriteSession($id,$data)
{
return$this->_cache->set($this->calculateKey($id),$data,$this->getTimeout());
}

会话写入处理程序。 不要直接调用这个方法。