PHP Class yii\web\CacheSession

The cache being used can be any cache application component. The ID of the cache application component is specified via [[cache]], 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 database as storage medium, DbSession is a better choice. The following example shows how you can configure the application to use CacheSession: Add the following to your application config under components: php 'session' => [ 'class' => 'yii\web\CacheSession', 'cache' => 'mycache', ]
Since: 2.0
Author: Qiang Xue ([email protected])
Inheritance: extends yii\web\Session
Show file Open project: yiisoft/yii2 Class Usage Examples

Public Properties

Property Type Description
$cache the cache object or the application component ID of the cache object. The session data will be stored using this cache object. After the CacheSession object is created, if you want to change this property, you should only assign it with a cache object. Starting from version 2.0.2, this can also be a configuration array for creating the object.

Public Methods

Method Description
destroySession ( string $id ) : boolean Session destroy handler.
getUseCustomStorage ( ) : boolean Returns a value indicating whether to use custom session storage.
init ( ) Initializes the application component.
readSession ( string $id ) : string Session read handler.
writeSession ( string $id, string $data ) : boolean Session write handler.

Protected Methods

Method Description
calculateKey ( string $id ) : mixed Generates a unique key used for storing session data in cache.

Method Details

calculateKey() protected method

Generates a unique key used for storing session data in cache.
protected calculateKey ( string $id ) : mixed
$id string session variable name
return mixed a safe cache key associated with the session variable name

destroySession() public method

Do not call this method directly.
public destroySession ( string $id ) : boolean
$id string session ID
return boolean whether session is destroyed successfully

getUseCustomStorage() public method

This method overrides the parent implementation and always returns true.
public getUseCustomStorage ( ) : boolean
return boolean whether to use custom storage.

init() public method

Initializes the application component.
public init ( )

readSession() public method

Do not call this method directly.
public readSession ( string $id ) : string
$id string session ID
return string the session data

writeSession() public method

Do not call this method directly.
public writeSession ( string $id, string $data ) : boolean
$id string session ID
$data string session data
return boolean whether session write is successful

Property Details

$cache public property

the cache object or the application component ID of the cache object. The session data will be stored using this cache object. After the CacheSession object is created, if you want to change this property, you should only assign it with a cache object. Starting from version 2.0.2, this can also be a configuration array for creating the object.
public $cache