ZF-6746: Cache in Zend_Paginator not working


Zend_Paginator makes cache ids from spl_object_hash($this), which changes throught HTTP request making Paginator unable to load its data back from cache, and also making it duplicate them in the cache.


Related to "Zend_Paginator makes cache ids from spl_object_hash($this)":

it gives me same cache id for same adapter made from 2 different Zend_Db_Table_Select objects to test:

$table = new zend_db_tabe(); $select1 = $table->select()-where('some_field_1 = ?', 'some value'); $select2 = $table->select()-where('some_field_1 = ?', 'some other value');

$paginaor = new Zend_Paginator::Factory($select1); and $paginaor = new Zend_Paginator::Factory($select2);

return the same cache id, even though the results of the 2 selects are different.

is it possible to cache the total number of items? I noticed that the select that counts the total number of items that need to be paginated is not cached.

Fixed in r15883 Warning, could lead to BC breaks with old cache entries as the tagging system has been reviewed and improved. Tests are welcome

When using Zend_Db_Profiler_Fierbug there are a few properties that store microtime values which when serializing the adapter cause it to produce a different hash value each time. Because this hash value is used to identify what cached data to load, Zend_Cache is unable to find any cache associated to this identifier.

This cache stuff broken again in 1.9.1 Zend_Paginator_Adapter_DbTableSelect public function getItems($offset, $itemCountPerPage) { echo md5(serialize($this));echo "
"; $this->_select->limit($itemCountPerPage, $offset); echo md5(serialize($this));echo "
"; return $this->_select->getTable()->fetchAll($this->_select); }

this will show you issue, you will see two different strings and paginator will never load data from cache.

Caching in Paginator is relatively tricky, which is one of the reasons why we didn't implement it initially.

ivan: Could you open a new issue for this?

julien: Do you want to look into this? Or shall I give it a go later today?