function testClearCache()
{
$this->CacheData->Behaviors->attach('Cacher.Cache', array('auto' => true));
$results = $this->CacheData->find('all', array('conditions' => array('CacheData.name LIKE' => '%cache%')));
$results = Set::extract('/CacheData/name', $results);
$expected = array('A Cached Thing', 'Cache behavior');
$this->assertEquals($results, $expected);
$ds = ConnectionManager::getDataSource('cacher');
$this->CacheData->find('all', array('conditions' => array('CacheData.name LIKE' => '123')));
$this->CacheData->find('all', array('conditions' => array('CacheData.name LIKE' => '456')));
$map = Cache::read('map', 'default');
$results = count($map[$ds->source->configKeyName][$this->CacheData->alias]);
$this->assertEquals($results, 3);
foreach ($map[$ds->source->configKeyName][$this->CacheData->alias] as $key) {
$this->assertTrue(Cache::read($key, 'default') !== false, 'Failed checking key ' . $key);
}
// test clearing 1 cached query
$this->CacheData->clearCache(array('conditions' => array('CacheData.name LIKE' => '456')));
$map = Cache::read('map', 'default');
$results = count($map[$ds->source->configKeyName][$this->CacheData->alias]);
$this->assertEquals($results, 2);
foreach ($map[$ds->source->configKeyName][$this->CacheData->alias] as $key) {
$this->assertTrue(Cache::read($key, 'default') !== false, 'Failed checking key ' . $key);
}
// test clearing all
$this->CacheData->clearCache();
$map = Cache::read('map', 'default');
$results = count($map[$ds->source->configKeyName][$this->CacheData->alias]);
$this->assertEquals($results, 0);
foreach ($map[$ds->source->configKeyName][$this->CacheData->alias] as $key) {
$this->assertTrue(Cache::read($key, 'default') !== false, 'Failed checking key ' . $key);
}
}