ZF-11318: Zend_Paginator cache ( related to ZF-10447 )


This is related to

But I hope this may help.

Using the standard serialization of the adapter I noticed two things ( other than the DB reconnect ): - 1) Zend_Paginator::_getCacheInternalId() is called three times ( in my usage ), the first md5 serialization differs from the other two, probably because the last two modify the _select of the adapter. 2) The md5 changes on every subsequent page load, why I don't know at this stage.

I tried moving away from the serialization of the object to a string representation of the _select of the adapter ( added a getSelect() method ) this had the same effect as 1) but the subsequent loads did provide the same hashed strings, which was an improvement.

I then added a static cache within the Zend_Paginator::_getCacheInternalId() method which stored the initial hash ( probably the one before the paging changed the select ) and this seems to work.

    protected function _getCacheInternalId()
        static $cache = array();
        $adapter_namespace = get_class( $this->getAdapter() );
        if ( !array_key_exists( $adapter_namespace, $cache ) ) {
            $cache[$adapter_namespace] = md5(serialize(array(
        return $cache[$adapter_namespace];

The page number is still added to the md5 so it should still be unique.

Whether this is a valid solution I really don't know at this stage but thought it worth mentioning. [edit]Code modified to allow caches for different adapter namespaces[/edit]


No comments to display