mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Preventing cache collisions by adding the the datasource key
This commit is contained in:
parent
18b335a605
commit
e5eb7b490e
2 changed files with 57 additions and 1 deletions
|
@ -2172,7 +2172,8 @@ class DboSource extends DataSource {
|
|||
$model->alias,
|
||||
$virtualFields,
|
||||
$fields,
|
||||
$quote
|
||||
$quote,
|
||||
ConnectionManager::getSourceName($this)
|
||||
);
|
||||
$cacheKey = md5(serialize($cacheKey));
|
||||
if ($return = $this->cacheMethod(__FUNCTION__, $cacheKey)) {
|
||||
|
|
|
@ -53,6 +53,30 @@ class DboTestSource extends DboSource {
|
|||
|
||||
}
|
||||
|
||||
class DboSecondTestSource extends DboSource {
|
||||
|
||||
public $startQuote = '_';
|
||||
|
||||
public $endQuote = '_';
|
||||
|
||||
public function connect($config = array()) {
|
||||
$this->connected = true;
|
||||
}
|
||||
|
||||
public function mergeAssociation(&$data, &$merge, $association, $type, $selfJoin = false) {
|
||||
return parent::_mergeAssociation($data, $merge, $association, $type, $selfJoin);
|
||||
}
|
||||
|
||||
public function setConfig($config = array()) {
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function setConnection($conn) {
|
||||
$this->_connection = $conn;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* DboSourceTest class
|
||||
*
|
||||
|
@ -790,6 +814,37 @@ class DboSourceTest extends CakeTestCase {
|
|||
$this->assertTrue(empty(DboTestSource::$methodCache['fields']), 'Cache not empty');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* test that fields() method cache detects datasource changes
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFieldsCacheKeyWithDatasourceChange() {
|
||||
ConnectionManager::create('firstschema', array(
|
||||
'datasource' => 'DboTestSource'
|
||||
));
|
||||
ConnectionManager::create('secondschema', array(
|
||||
'datasource' => 'DboSecondTestSource'
|
||||
));
|
||||
Cache::delete('method_cache', '_cake_core_');
|
||||
DboTestSource::$methodCache = array();
|
||||
$Article = ClassRegistry::init('Article');
|
||||
|
||||
$Article->setDataSource('firstschema');
|
||||
$ds = $Article->getDataSource();
|
||||
$ds->cacheMethods = true;
|
||||
$first = $ds->fields($Article, null, array('title', 'body', 'published'));
|
||||
|
||||
$Article->setDataSource('secondschema');
|
||||
$ds = $Article->getDataSource();
|
||||
$ds->cacheMethods = true;
|
||||
$second = $ds->fields($Article, null, array('title', 'body', 'published'));
|
||||
|
||||
$this->assertNotEquals($first, $second);
|
||||
$this->assertEquals(2, count(DboTestSource::$methodCache['fields']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that group works without a model
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue