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 (qiang.xue@gmail.com)
Inheritance: extends yii\web\Session
Esempio n. 1
0
 public function testCacheSession()
 {
     $session = new CacheSession();
     $session->writeSession('test', 'sessionData');
     $this->assertEquals('sessionData', $session->readSession('test'));
     $session->destroySession('test');
     $this->assertEquals('', $session->readSession('test'));
 }
Esempio n. 2
0
 /**
  * Initializes the application component.
  */
 public function init()
 {
     parent::init();
     if (!$this->cache instanceof HSCache) {
         throw new InvalidConfigException('Cache component for session must be instance of ' . HSCache::className());
     }
     $this->cache = clone $this->cache;
     $this->cache->group = $this->group;
 }
Esempio n. 3
0
 public function init()
 {
     parent::init();
 }
Esempio n. 4
0
 /**
  * Initializes the application component.
  */
 public function init()
 {
     parent::init();
     $this->cache = Instance::ensure($this->cache, Cache::className());
     $this->cache->keyPrefix = '';
 }