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

Commit

Permalink
Merge pull request zendframework/zendframework#9 from weierophinney/f…
Browse files Browse the repository at this point in the history
…eature/cache_beta2

Feature/cache beta2
  • Loading branch information
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions src/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
Iterator,
IteratorAggregate,
Traversable,
Zend\Cache\Frontend\Core as CacheCore,
Zend\Cache\Storage\Adapter as CacheAdapter,
Zend\Db\Select as DbSelect,
Zend\Db\Table\AbstractRowset as DbAbstractRowset,
Zend\Db\Table\Select as DbTableSelect,
Expand Down Expand Up @@ -96,7 +96,7 @@ class Paginator implements Countable, IteratorAggregate
/**
* Cache object
*
* @var CacheCore
* @var CacheAdapter
*/
protected static $_cache;

Expand Down Expand Up @@ -323,9 +323,9 @@ public static function setDefaultItemCountPerPage($count)
/**
* Sets a cache object
*
* @param CacheCore $cache
* @param CacheAdapter $cache
*/
public static function setCache(CacheCore $cache)
public static function setCache(CacheAdapter $cache)
{
self::$_cache = $cache;
}
Expand Down Expand Up @@ -476,14 +476,17 @@ public function clearPageItemCache($pageNumber = null)
}

if (null === $pageNumber) {
foreach (self::$_cache->getIdsMatchingTags(array($this->_getCacheInternalId())) as $id) {
$cacheIds = self::$_cache->find(CacheAdapter::MATCH_TAGS_OR, array('tags' => array(
$this->_getCacheInternalId()
)));
foreach ($cacheIds as $id) {
if (preg_match('|'.self::CACHE_TAG_PREFIX."(\d+)_.*|", $id, $page)) {
self::$_cache->remove($this->_getCacheId($page[1]));
self::$_cache->removeItem($this->_getCacheId($page[1]));
}
}
} else {
$cleanId = $this->_getCacheId($pageNumber);
self::$_cache->remove($cleanId);
self::$_cache->removeItem($cleanId);
}
return $this;
}
Expand Down Expand Up @@ -693,7 +696,7 @@ public function getItemsByPage($pageNumber)
$pageNumber = $this->normalizePageNumber($pageNumber);

if ($this->_cacheEnabled()) {
$data = self::$_cache->load($this->_getCacheId($pageNumber));
$data = self::$_cache->getItem($this->_getCacheId($pageNumber));
if ($data !== false) {
return $data;
}
Expand All @@ -714,7 +717,11 @@ public function getItemsByPage($pageNumber)
}

if ($this->_cacheEnabled()) {
self::$_cache->save($items, $this->_getCacheId($pageNumber), array($this->_getCacheInternalId()));
self::$_cache->setItem(
$this->_getCacheId($pageNumber),
$items,
array('tags' => array($this->_getCacheInternalId()))
);
}

return $items;
Expand Down Expand Up @@ -802,10 +809,13 @@ public function getPageItemCache()
{
$data = array();
if ($this->_cacheEnabled()) {
foreach (self::$_cache->getIdsMatchingTags(array($this->_getCacheInternalId())) as $id) {
if (preg_match('|'.self::CACHE_TAG_PREFIX."(\d+)_.*|", $id, $page)) {
$data[$page[1]] = self::$_cache->load($this->_getCacheId($page[1]));
}
$cacheIds = self::$_cache->find(CacheAdapter::MATCH_TAGS_OR, array(
'tags' => array($this->_getCacheInternalId()),
));
foreach ($cacheIds as $id) {
if (preg_match('|'.self::CACHE_TAG_PREFIX."(\d+)_.*|", $id, $page)) {
$data[$page[1]] = self::$_cache->getItem($this->_getCacheId($page[1]));
}
}
}
return $data;
Expand Down

0 comments on commit b3e8431

Please sign in to comment.