Issues

ZF-12211: Zend_Paginator Cache with DbSelect adapter

Issue Type: Bug Created: 2012-05-18T12:06:45.000+0000 Last Updated: 2012-05-18T15:36:26.000+0000 Status: Open Fix version(s): Reporter: Alexandru Pruteanu (p.alex) Assignee: Jurrien Stutterheim (norm2782) Tags: - Zend_Paginator

Related issues: Attachments:

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.

<pre class="highlight">
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

<pre class="highlight">
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.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts