CCacheHttpSession
鍖 | 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鏉ユ寚瀹氱殑锛岄粯璁ゅ兼槸鈥榗ache鈥欍
瑕佹敞鎰忕殑鏄紝缂撳瓨浠嬭川鏄緢瀹规槗鏀瑰彉鐨勶紝 閭e氨鎰忓懗鐫瀛樺偍鍦ㄤ笂闈㈢殑鏁版嵁浼氳鍒锋帀銆傚洜姝わ紝浣犲繀椤荤‘瀹氳繖涓粍浠朵娇鐢ㄧ殑瀛樺偍鏄鏄撴敼鍙樸 濡傛灉浣犳兂瑕佺敤CDbCache浣滀负瀛樺偍浠嬭川锛CDbHttpSession 浼氭槸涓涓洿濂界殑閫夋嫨銆
鍙鏄疄鐜颁簡ICache鎺ュ彛鐨勫簲鐢ㄧ粍浠堕兘鍙互浣滀负缂撳瓨銆 杩欎釜缂撳瓨ID鏄氳繃cacheID鏉ユ寚瀹氱殑锛岄粯璁ゅ兼槸鈥榗ache鈥欍
瑕佹敞鎰忕殑鏄紝缂撳瓨浠嬭川鏄緢瀹规槗鏀瑰彉鐨勶紝 閭e氨鎰忓懗鐫瀛樺偍鍦ㄤ笂闈㈢殑鏁版嵁浼氳鍒锋帀銆傚洜姝わ紝浣犲繀椤荤‘瀹氳繖涓粍浠朵娇鐢ㄧ殑瀛樺偍鏄鏄撴敼鍙樸 濡傛灉浣犳兂瑕佺敤CDbCache浣滀负瀛樺偍浠嬭川锛CDbHttpSession 浼氭槸涓涓洿濂界殑閫夋嫨銆
鍏叡灞炴
灞炴 | 绫诲瀷 | 鎻忚堪 | 瀹氫箟鍦 |
---|---|---|---|
autoStart | boolean | whether the session should be automatically started when the session application component is initialized, defaults to true. | CHttpSession |
behaviors | array | 杩欎釜搴旂敤缁勪欢闄勫姞鐨勮涓恒 杩欐琛屼负灏嗗湪搴旂敤缁勪欢璋冪敤init鏃堕檮鍔犲湪搴旂敤缁勪欢涓娿 璇峰弬鐓CModel::behaviors濡備綍鎸囧畾姝ゅ睘鎬у笺 | CApplicationComponent |
cacheID | string | 缂撳瓨搴旂敤缁勪欢ID銆傞粯璁ゆ槸鈥榗ache鈥欙紙鍘熷缂撳瓨搴旂敤缁勪欢銆傦級 | 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 | integer | the probability (percentage) that the gc (garbage collection) process is started on every session initialization, defaults to 1 meaning 1% chance. | CHttpSession |
isInitialized | boolean | 妫鏌ュ簲鐢ㄧ粍浠舵槸鍚﹀凡缁忓垵濮嬪寲銆 | 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 '/tmp'. | 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 | 杩斿洖涓涓硷紝鎸囩ず鏄惁浣跨敤鑷畾涔夌殑浼氳瘽瀛樺偍銆 | CCacheHttpSession |
useTransparentSessionID | boolean | whether 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 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() | 浼氳瘽閿姣佸鐞嗙▼搴忋 | CCacheHttpSession |
detachBehavior() | 浠庣粍浠朵腑鍒嗙涓涓涓恒 | CComponent |
detachBehaviors() | 浠庣粍浠朵腑鍒嗙鎵鏈夎涓恒 | CComponent |
detachEventHandler() | 鍒嗙涓涓瓨鍦ㄧ殑浜嬩欢澶勭悊绋嬪簭銆 | CComponent |
disableBehavior() | 绂佺敤涓涓檮鍔犺涓恒 | CComponent |
disableBehaviors() | 绂佺敤缁勪欢闄勫姞鐨勬墍鏈夎涓恒 | CComponent |
enableBehavior() | 鍚敤涓涓檮鍔犺涓恒 | CComponent |
enableBehaviors() | 鍚敤缁勪欢闄勫姞鐨勬墍鏈夎涓恒 | CComponent |
evaluateExpression() | 璁$畻涓涓狿HP琛ㄨ揪寮忥紝鎴栨牴鎹粍浠朵笂涓嬫枃鎵ц鍥炶皟銆 | 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() | 妫鏌hether the session has started | CHttpSession |
getIterator() | Returns an iterator for traversing the session variables. | CHttpSession |
getKeys() | 杩斿洖the list of session variable names | CHttpSession |
getSavePath() | 杩斿洖the current session save path, defaults to '/tmp'. | CHttpSession |
getSessionID() | 杩斿洖the current session ID | CHttpSession |
getSessionName() | 杩斿洖the current session name | CHttpSession |
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 path | CHttpSession |
setSessionID() | 璁剧疆the session ID for the current session | CHttpSession |
setSessionName() | 璁剧疆the session name for the current session, must be an alphanumeric string, defaults to PHPSESSID | CHttpSession |
setTimeout() | 璁剧疆the number of seconds after which data will be seen as 'garbage' and cleaned up | CHttpSession |
setUseTransparentSessionID() | 璁剧疆whether transparent sid support is enabled or not. | CHttpSession |
toArray() | CHttpSession | |
writeSession() | 浼氳瘽鍐欏叆澶勭悊绋嬪簭銆 | CCacheHttpSession |
灞炴ц缁
cacheID
灞炴
public string $cacheID;
缂撳瓨搴旂敤缁勪欢ID銆傞粯璁ゆ槸鈥榗ache鈥欙紙鍘熷缂撳瓨搴旂敤缁勪欢銆傦級
useCustomStorage
灞炴
鍙
public boolean getUseCustomStorage()
杩斿洖涓涓硷紝鎸囩ず鏄惁浣跨敤鑷畾涔夌殑浼氳瘽瀛樺偍銆 杩欎釜鏂规硶鏄鐩栦簡鐖剁被鏂规硶锛屾绘槸杩斿洖true銆
鏂规硶璇︾粏
calculateKey()
鏂规硶
protected string calculateKey(string $id)
| ||
$id | string | 浼氳瘽鍙橀噺鍚嶅瓧 |
{return} | string | 瀹夊叏鐨勭紦瀛橀敭鍊煎拰浼氳瘽鍙橀噺鍚嶅瓧 |
婧愮爜锛 framework/web/CCacheHttpSession.php#109 (鏄剧ず)
protected function calculateKey($id)
{
return self::CACHE_KEY_PREFIX.$id;
}
涓哄皢瑕佸瓨鍌ㄧ殑浼氬憳鏁版嵁鐢熸垚涓涓敮涓鐨勯敭鍚嶃
destroySession()
鏂规硶
public boolean destroySession(string $id)
| ||
$id | string | 浼氳瘽ID |
{return} | boolean | 浼氳瘽鏄惁琚垚鍔熼攢姣 |
婧愮爜锛 framework/web/CCacheHttpSession.php#99 (鏄剧ず)
public function destroySession($id)
{
return $this->_cache->delete($this->calculateKey($id));
}
浼氳瘽閿姣佸鐞嗙▼搴忋 涓嶈鐩存帴璋冪敤杩欎釜鏂规硶銆
getUseCustomStorage()
鏂规硶
public boolean getUseCustomStorage()
| ||
{return} | boolean | 鏄惁浣跨敤甯歌瀛樺偍銆 |
婧愮爜锛 framework/web/CCacheHttpSession.php#64 (鏄剧ず)
public function getUseCustomStorage()
{
return true;
}
杩斿洖涓涓硷紝鎸囩ず鏄惁浣跨敤鑷畾涔夌殑浼氳瘽瀛樺偍銆 杩欎釜鏂规硶鏄鐩栦簡鐖剁被鏂规硶锛屾绘槸杩斿洖true銆
init()
鏂规硶
public void init()
|
婧愮爜锛 framework/web/CCacheHttpSession.php#50 (鏄剧ず)
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();
}
鍒濆鍖栬繖涓簲鐢ㄧ粍浠躲 杩欎釜鏂规硶瑕嗙洊浜嗙埗绫绘柟娉曪紝涓昏鏄鏌ョ紦瀛樻槸鍚﹀彲鐢ㄣ
readSession()
鏂规硶
public string readSession(string $id)
| ||
$id | string | 浼氳瘽ID |
{return} | string | the 浼氳瘽鏁版嵁 |
婧愮爜锛 framework/web/CCacheHttpSession.php#75 (鏄剧ず)
public function readSession($id)
{
$data=$this->_cache->get($this->calculateKey($id));
return $data===false?'':$data;
}
浼氳瘽璇诲彇澶勭悊绋嬪簭銆 涓嶈鐩存帴璋冪敤杩欎釜鏂规硶銆
writeSession()
鏂规硶
public boolean writeSession(string $id, string $data)
| ||
$id | string | 浼氳瘽ID |
$data | string | 浼氳瘽鏁版嵁 |
{return} | boolean | 鏄惁鎴愬姛鍐欏叆浜嗕細璇濇暟鎹 |
婧愮爜锛 framework/web/CCacheHttpSession.php#88 (鏄剧ず)
public function writeSession($id,$data)
{
return $this->_cache->set($this->calculateKey($id),$data,$this->getTimeout());
}
浼氳瘽鍐欏叆澶勭悊绋嬪簭銆 涓嶈鐩存帴璋冪敤杩欎釜鏂规硶銆