Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge branch 'cache_interfaces' of https://github.com/marc-mabe/zf2 i…
Browse files Browse the repository at this point in the history
…nto feature/cache-simplification
  • Loading branch information
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions src/SaveHandler/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -100,7 +103,7 @@ public function close()
*/
public function read($id)
{
return $this->getStorageAdapter()->getItem($id);
return $this->getCacheStorge()->getItem($id);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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;
}
}

0 comments on commit 6ade9b9

Please sign in to comment.