ZF-8019: Zend_Paginator get Cache ID Error


File Zend_Paginator.php method: public function getItemsByPage($pageNumber) on line 737


Method will check if cache enable and cache ID exists it will return the cached data.

if ($this->_cacheEnabled()) {
            $data = self::$_cache->load($this->_getCacheId($pageNumber));
            if ($data !== false) {
                return $data;

If cache is enable but does not exists It will get data and cached with a cache ID.

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

But when I echo $this->_getCacheId($pageNumber) at first check step and save cache step It gives two defference cache ID so Zend_Paginator cache feature does not work, It just generate a file or overide cached file without using cached data . Here my code

if ($this->_cacheEnabled()) {
//ouput cache name for checking it
    echo $this->_getCacheId($pageNumber) .'
'; $data = self::$_cache->load($this->_getCacheId($pageNumber)); if ($data !== false) { return $data; } } if ($this->_cacheEnabled()) { //ouput cache name for checking it echo $this->_getCacheId($pageNumber) .'
'; self::$_cache->save($items, $this->_getCacheId($pageNumber), array($this->_getCacheInternalId())); }

I have checked It on Zend_Paginator_Adapter_DbSelect with the both Pdo_mysql and MySqli Db Adaptors and Zend_Db option profiler was turned off, Please check and fix this problem plz


this is my way,

<?php class PP_Paginator_Adapter_DbSelect extends Zend_Paginator_Adapter_DbSelect { public function getSelect() { return $this->_select; } } ?> <?php class PP_Paginator extends Zend_Paginator { /** * FIX Zend_Paginator _getCacheInternalId ERROR * */ protected function _getCacheInternalId() { $item_count_per_page = $this->getItemCountPerPage(); return md5(serialize( array( strval($this->getAdapter()->getSelect()->limit()), ($pageNumber - 1) * $item_count_per_page, $item_count_per_page))); } } ?>

This issue is still open in 1.10.2

Thanks @ wl nroe

Your solution could resolve the problem. I tested a shorter version and it seems to work well.

class My_Paginator extends Zend_Paginator
    protected function _getCacheInternalId()
        return md5(serialize(strval($this->getAdapter()->getSelect()->limit())));

@Martin Meißner your solution is not perfect, there are some more adapters without the database interface

fixed with r22302