Skip to content

Commit

Permalink
Add DboSource::flushQueryCache()
Browse files Browse the repository at this point in the history
  • Loading branch information
chinpei215 committed Apr 18, 2016
1 parent 1706b89 commit 1826b4c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/Cake/Model/Datasource/DboSource.php
Expand Up @@ -3540,6 +3540,15 @@ public function introspectType($value) {
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
*
Expand Down
16 changes: 16 additions & 0 deletions lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php
Expand Up @@ -1810,4 +1810,20 @@ public function testHasOneAfterFind() {
$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);
}
}

0 comments on commit 1826b4c

Please sign in to comment.