Are you using custom caching or built-in ? I've never had problems with component cache.
I've put your snippet inside com_content and it worked despite cache was on.
You can delete all site cache via model:
JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR.'/components/com_cache/models', 'Cache');
$model = JModelLegacy::getInstance('Cache', 'CacheModel');
$model->clean();
//$model->clean('_system'); SYSTEM_CACHE_ONLY
This is equivalent to:
$cache = JCache::getInstance('''output',
[
'defaultgroup'=>'',
'cachebase' => JPATH_SITE.'/cache' or JPATH_ADMINISTRATOR for admin cache
]);
$cache->clean();
System cache will rebuild _system as quick as you hit administrator area again :)