Merge pull request #8663 from chinpei215/2.next-query-cache

2.next Add DboSource::flushQueryCache()
This commit is contained in:
Mark Story 2016-04-18 18:03:37 -04:00
commit b71e93a16e
2 changed files with 25 additions and 0 deletions

View file

@ -3540,6 +3540,15 @@ class DboSource extends DataSource {
return 'string'; return 'string';
} }
/**
* Empties the query caches.
*
* @return void
*/
public function flushQueryCache() {
$this->_queryCache = array();
}
/** /**
* Writes a new key for the in memory sql query cache * Writes a new key for the in memory sql query cache
* *

View file

@ -1810,4 +1810,20 @@ class DboSourceTest extends CakeTestCase {
$User->Article = $Article; $User->Article = $Article;
$User->find('first', array('conditions' => array('User.id' => 1), 'recursive' => 2)); $User->find('first', array('conditions' => array('User.id' => 1), 'recursive' => 2));
} }
/**
* Test that flushQueryCache works as expected
*
* @return void
*/
public function testFlushQueryCache() {
$this->db->flushQueryCache();
$this->db->query('SELECT 1');
$this->db->query('SELECT 1');
$this->db->query('SELECT 2');
$this->assertAttributeCount(2, '_queryCache', $this->db);
$this->db->flushQueryCache();
$this->assertAttributeCount(0, '_queryCache', $this->db);
}
} }