From a33253940d0f7b9a360cf9a597a9c4985d121aa2 Mon Sep 17 00:00:00 2001 From: Marc Bennewitz Date: Mon, 28 May 2012 22:44:03 +0200 Subject: [PATCH] updated Zend\Session\SaveHandler\Cache to use the simplified cache API --- src/SaveHandler/Cache.php | 49 +++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/src/SaveHandler/Cache.php b/src/SaveHandler/Cache.php index cb94f9a7..cab7a6b4 100644 --- a/src/SaveHandler/Cache.php +++ b/src/SaveHandler/Cache.php @@ -20,8 +20,11 @@ namespace Zend\Session\SaveHandler; -use Zend\Cache\Storage\Adapter\AdapterInterface as StorageAdapter; -use Zend\Session\Exception; +use Zend\Cache\Storage\ClearExpiredInterface; + +use Zend\Cache\Storage\StorageInterface as CacheStorage, + Zend\Cache\Storage\ClearExpiredInterface as ClearExpiredCacheStorage, + Zend\Session\Exception; /** * Cache session save handler @@ -49,21 +52,21 @@ class Cache implements SaveHandlerInterface protected $sessionName; /** - * The cache storage adapter - * @var StorageAdapter + * The cache storage + * @var CacheStorage */ - protected $storageAdapter; + protected $cacheStorage; /** * Constructor * - * @param Zend\Cache\Storage\Adapter\AdapterInterface $storageAdapter + * @param CacheStorage $cacheStorage * @return void - * @throws Zend\Session\Exception\ExceptionInterface + * @throws Exception\ExceptionInterface */ - public function __construct(StorageAdapter $storageAdapter) + public function __construct(CacheStorage $cacheStorage) { - $this->setStorageAdapter($storageAdapter); + $this->setCacheStorage($cacheStorage); } /** @@ -100,7 +103,7 @@ public function close() */ public function read($id) { - return $this->getStorageAdapter()->getItem($id); + return $this->getCacheStorge()->getItem($id); } /** @@ -112,7 +115,7 @@ public function read($id) */ public function write($id, $data) { - return $this->getStorageAdapter()->setItem($id, $data); + return $this->getCacheStorge()->setItem($id, $data); } /** @@ -123,40 +126,42 @@ public function write($id, $data) */ public function destroy($id) { - return $this->getStorageAdapter()->removeItem($id); + return $this->getCacheStorge()->removeItem($id); } /** * Garbage Collection * * @param int $maxlifetime - * @return true + * @return boolean */ public function gc($maxlifetime) { + $cache = $this->getCacheStorge(); + if ($cache instanceof ClearExpiredCacheStorage) { + return $cache->clearExpired(); + } return true; } /** - * Set cache storage adapter - * - * Allows passing a string class name or StorageAdapter object. + * Set cache storage * - * @param Zend\Cache\Storage\Adapter\AdapterInterface + * @param CacheStorage * @return void */ - public function setStorageAdapter(StorageAdapter $storageAdapter) + public function setCacheStorage(CacheStorage $cacheStorage) { - $this->storageAdapter = $storageAdapter; + $this->cacheStorage = $cacheStorage; } /** * Get Cache Storage Adapter Object * - * @return Zend\Cache\Storage\Adapter\AdapterInterface + * @return CacheStorage */ - public function getStorageAdapter() + public function getCacheStorge() { - return $this->storageAdapter; + return $this->cacheStorage; } }