Making DboSource::fields() use cacheMethod() so it respects $cacheMethods.

Test added.
Fixes #1211
This commit is contained in:
mark_story 2010-10-20 22:28:31 -04:00
parent 077d1c5ad5
commit 498417203b
2 changed files with 17 additions and 3 deletions

View file

@ -1958,8 +1958,8 @@ class DboSource extends DataSource {
$quote
);
$cacheKey = crc32(serialize($cacheKey));
if (isset($this->methodCache[__FUNCTION__][$cacheKey])) {
return $this->methodCache[__FUNCTION__][$cacheKey];
if ($return = $this->cacheMethod(__FUNCTION__, $cacheKey)) {
return $return;
}
$allFields = empty($fields);
if ($allFields) {
@ -2049,7 +2049,7 @@ class DboSource extends DataSource {
if (!empty($virtual)) {
$fields = array_merge($fields, $this->_constructVirtualFields($model, $alias, $virtual));
}
return $this->methodCache[__FUNCTION__][$cacheKey] = array_unique($fields);
return $this->cacheMethod(__FUNCTION__, $cacheKey, array_unique($fields));
}
/**

View file

@ -4577,4 +4577,18 @@ class DboSourceTest extends CakeTestCase {
$result = $Article->find('all');
$this->assertTrue(is_array($result));
}
/**
* test that fields() is using methodCache()
*
* @return void
*/
function testFieldsUsingMethodCache() {
$this->testDb->cacheMethods = false;
$this->assertTrue(empty($this->testDb->methodCache['fields']), 'Cache not empty');
$Article =& ClassRegistry::init('Article');
$this->testDb->fields($Article, null, array('title', 'body', 'published'));
$this->assertTrue(empty($this->testDb->methodCache['fields']), 'Cache not empty');
}
}