CCacheHttpSession
包 | system.web |
---|---|
继承 | class CCacheHttpSession » CHttpSession » CApplicationComponent » CComponent |
实现 | Countable, ArrayAccess, Traversable, IteratorAggregate, IApplicationComponent |
可用自 | 1.0 |
源码 | framework/web/CCacheHttpSession.php |
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 |
属性详情
the ID of the cache application component. Defaults to 'cache' (the primary cache application component.)
Returns a value indicating whether to use custom session storage. This method overrides the parent implementation and always returns true.
方法详情
protected string calculateKey(string $id)
| ||
$id | string | session variable name |
{return} | string | a safe cache key associated with the session variable name |
protected function calculateKey($id)
{
return self::CACHE_KEY_PREFIX.$id;
}
Generates a unique key used for storing session data in cache.
public boolean destroySession(string $id)
| ||
$id | string | session ID |
{return} | boolean | true if no error happens during deletion |
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
public boolean getUseCustomStorage()
| ||
{return} | boolean | whether to use custom storage. |
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.
public void init()
|
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.
public string readSession(string $id)
| ||
$id | string | session ID |
{return} | string | the session data |
public function readSession($id)
{
$data=$this->_cache->get($this->calculateKey($id));
return $data===false?'':$data;
}
Session read handler. Do not call this method directly.
public boolean writeSession(string $id, string $data)
| ||
$id | string | session ID |
$data | string | session data |
{return} | boolean | whether session write is successful |
public function writeSession($id,$data)
{
return $this->_cache->set($this->calculateKey($id),$data,$this->getTimeout());
}
Session write handler. Do not call this method directly.