ZF-12211: Zend_Paginator Cache with DbSelect adapter
Description
When enabling Zend_Paginator with Zend_Cache and DbSelect paginator adapter, the cached file md5() hash is always different. So you get only cache miss. The problem is here.
public function getItemsByPage($pageNumber)
{
$pageNumber = $this->normalizePageNumber($pageNumber);
// THE HASH IS DIFFERENT HERE FROM -> see next down
if ($this->_cacheEnabled()) {
$data = self::$_cache->load($this->_getCacheId($pageNumber));
if ($data !== false) {
return $data;
}
}
$offset = ($pageNumber - 1) * $this->getItemCountPerPage();
$items = $this->_adapter->getItems($offset, $this->getItemCountPerPage());
$filter = $this->getFilter();
if ($filter !== null) {
$items = $filter->filter($items);
}
if (!$items instanceof Traversable) {
$items = new ArrayIterator($items);
}
// FROM HERE
if ($this->_cacheEnabled()) {
self::$_cache->save($items, $this->_getCacheId($pageNumber), array($this->_getCacheInternalId()));
}
return $items;
}
All this because of the _adapter when serializing it.
Here is the problem
public function getItems($offset, $itemCountPerPage)
{
// THIS PORTION OF CODE
$this->_select->limit($itemCountPerPage, $offset);
return $this->_select->query()->fetchAll();
}
After this function the _adapter changes because of $this->_select->limit($itemCountPerPage, $offset); So the cached file hash is always different
Comments
Posted by Frank Brückner (frosch) on 2012-05-18T15:36:25.000+0000
Code tags added.