Skip to content

Commit 1826b4c

Browse files
committed
Add DboSource::flushQueryCache()
1 parent 1706b89 commit 1826b4c

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/Cake/Model/Datasource/DboSource.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3540,6 +3540,15 @@ public function introspectType($value) {
35403540
return 'string';
35413541
}
35423542

3543+
/**
3544+
* Empties the query caches.
3545+
*
3546+
* @return void
3547+
*/
3548+
public function flushQueryCache() {
3549+
$this->_queryCache = array();
3550+
}
3551+
35433552
/**
35443553
* Writes a new key for the in memory sql query cache
35453554
*

lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1810,4 +1810,20 @@ public function testHasOneAfterFind() {
18101810
$User->Article = $Article;
18111811
$User->find('first', array('conditions' => array('User.id' => 1), 'recursive' => 2));
18121812
}
1813+
1814+
/**
1815+
* Test that flushQueryCache works as expected
1816+
*
1817+
* @return void
1818+
*/
1819+
public function testFlushQueryCache() {
1820+
$this->db->flushQueryCache();
1821+
$this->db->query('SELECT 1');
1822+
$this->db->query('SELECT 1');
1823+
$this->db->query('SELECT 2');
1824+
$this->assertAttributeCount(2, '_queryCache', $this->db);
1825+
1826+
$this->db->flushQueryCache();
1827+
$this->assertAttributeCount(0, '_queryCache', $this->db);
1828+
}
18131829
}

0 commit comments

Comments
 (0)