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
Afficher le fichier Open project: yiisoft/yii2 Class Usage Examples

Méthodes publiques

Свойство 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.

Méthodes publiques

Méthode 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.

Méthodes protégées

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

Method Details

calculateKey() protected méthode

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

destroySession() public méthode

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

getUseCustomStorage() public méthode

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

init() public méthode

Initializes the application component.
public init ( )

readSession() public méthode

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

writeSession() public méthode

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

Property Details

$cache public_oe 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