Add DboSource::flushQueryCache()

This commit is contained in:
chinpei215 2016-04-19 00:01:06 +09:00
parent 1706b89915
commit 1826b4cb08
2 changed files with 25 additions and 0 deletions

View file

@ -3540,6 +3540,15 @@ class DboSource extends DataSource {
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
*

View file

@ -1810,4 +1810,20 @@ class DboSourceTest extends CakeTestCase {
$User->Article = $Article;
$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);
}
}