ZF-10447: Paginator and cache


Hi all. I'll be brief.

First problem: please see my last comment at http://framework.zend.com/issues/browse/ZF-6989 because that problem is still on even if the task is closed.

The second problem:

protected function _getCacheInternalId()
    return md5(serialize(array(
        $this->getAdapter(), $this->getItemCountPerPage())));

is a bad ideea. By serializing the paginator adapter the db adapter calls __sleep which sets the isConnected flag to false. The next call to the db makes a new connection to the db and [this is what happened to me] can loose any temporary tables i created. The answer to this problem is fixing the first one.



<?php /** * consider $frontendFileOptions and $backendFileOptions set and corect */ $cache = Zend_Cache::factory('Core', 'File', $frontendFileOptions, $backendFileOptions);

$db = Zend_Db::factory(_DB_ADAPTER, array( 'host' => _DB_HOST, 'port' => _DB_PORT, 'username' => _DB_USERNAME, 'password' => _DB_PASSWORD, 'dbname' => _DB_DATABASE, 'profiler' => _DB_PROFILER ));

$db->query(" CREATE TEMPORARY TABLE some_table ( id mediumint(8) unsigned NOT NULL, PRIMARY KEY (id) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 ");

$db->query(" INSERT INTO some_table SET id = 5 ");

$select = new Zend_Db_Select($db); $select->from('a')->setIntegrityCheck(false)->joinLeft('some_table', 'a.id = some_table.id');

$paginator = new Zend_Paginator::factory($select); $paginator->setCacheEnabled(true)->setCache($cache); /** * by rendering the paginator in the view the temporary table is not know amymore. */