|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
-
-
- namespace yii\web;
-
- use Yii;
- use yii\caching\Cache;
- use yii\di\Instance;
-
-
- class CacheSession extends Session
- {
-
-
- public $cache = 'cache';
-
-
-
-
- public function init()
- {
- parent::init();
- $this->cache = Instance::ensure($this->cache, Cache::className());
- }
-
-
-
- public function getUseCustomStorage()
- {
- return true;
- }
-
-
-
- public function readSession($id)
- {
- $data = $this->cache->get($this->calculateKey($id));
-
- return $data === false ? '' : $data;
- }
-
-
-
- public function writeSession($id, $data)
- {
- return $this->cache->set($this->calculateKey($id), $data, $this->getTimeout());
- }
-
-
-
- public function destroySession($id)
- {
- return $this->cache->delete($this->calculateKey($id));
- }
-
-
-
- protected function calculateKey($id)
- {
- return [__CLASS__, $id];
- }
- }
|