3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Session\SaveHandler
;
12 use Zend\Cache\Storage\ClearExpiredInterface
as ClearExpiredCacheStorage
;
13 use Zend\Cache\Storage\StorageInterface
as CacheStorage
;
16 * Cache session save handler
18 class Cache
implements SaveHandlerInterface
25 protected $sessionSavePath;
32 protected $sessionName;
38 protected $cacheStorage;
43 * @param CacheStorage $cacheStorage
45 public function __construct(CacheStorage
$cacheStorage)
47 $this->setCacheStorage($cacheStorage);
53 * @param string $savePath
57 public function open($savePath, $name)
59 // @todo figure out if we want to use these
60 $this->sessionSavePath
= $savePath;
61 $this->sessionName
= $name;
71 public function close()
82 public function read($id)
84 return $this->getCacheStorage()->getItem($id);
94 public function write($id, $data)
96 return $this->getCacheStorage()->setItem($id, $data);
105 public function destroy($id)
107 return $this->getCacheStorage()->removeItem($id);
113 * @param int $maxlifetime
116 public function gc($maxlifetime)
118 $cache = $this->getCacheStorage();
119 if ($cache instanceof ClearExpiredCacheStorage
) {
120 return $cache->clearExpired();
128 * @param CacheStorage $cacheStorage
131 public function setCacheStorage(CacheStorage
$cacheStorage)
133 $this->cacheStorage
= $cacheStorage;
140 * @return CacheStorage
142 public function getCacheStorage()
144 return $this->cacheStorage
;
148 * @deprecated Misspelled method - use getCacheStorage() instead
150 public function getCacheStorge()
152 return $this->getCacheStorage();