ZF-9947: Zend_Paginator - problem with _getCacheInternalId


  1. My controller:

    public function indexAction()

        $typeTopics = $this->_getParam('type');
        $select = $topics->prepareSelect( array($typeTopics=>0) );

        $paginator = new Zend_Paginator( new Zend_Paginator_Adapter_DbTableSelect( $select ) );
        $paginator->setCurrentPageNumber( $this->getRequest()->getParam( 'page', 1 ) );
        $paginator->setItemCountPerPage( 40 );

        $this->view->paginator = $paginator;

  1. In Zend_Paginator added :

    protected function _getCacheInternalId()
        echo md5(serialize(array(
'; return md5(serialize(array( spl_object_hash($this->getAdapter()), $this->getItemCountPerPage() ))); }
  1. I removed all cache
  2. Refresh page with url params: /type/new/page/1: _getCacheInternalId return: 322da30ae524a49ef490e50e873ab732 /type/popular/page/1: _getCacheInternalId return: b787e582a878f61ec149875f5484cfd6 ok we have different hash
  3. I reload pages again and now paginator reading from cache: /type/new/page/1: _getCacheInternalId return: b787e582a878f61ec149875f5484cfd6 /type/popular/page/1: _getCacheInternalId return: b787e582a878f61ec149875f5484cfd6 hash is the same for both urls, if disable cache everythings works good :(


I have the same problem in 1.10.6.

I can't say why, but on a Windows 7 computer I get a different internal cache id but on a computer with linux debian I always get the same internal cache id.

Edit: On the Windows 7 is PHP version 5.3.1 installed and on the linux debian PHP version 5.2.8. Is it possible, that the PHP version is the problem?

Have a look on my comment for issue ZF-9940. Caching should now working fine. This issue can be closed.

I'm still observing this bug in the latest release.

I took a look in to this issue and managed to hack caching to work as expected in Zend_Paginator as follows (diff to trunk r24489):

Index: library/Zend/Paginator.php

--- library/Zend/Paginator.php (revision 24490) +++ library/Zend/Paginator.php (working copy) @@ -772,8 +772,10 @@ { $pageNumber = $this->normalizePageNumber($pageNumber);

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

    @@ -794,7 +796,7 @@ }

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

Not sure if this is the solution but it worked for me.

Reopened due to comments