So, here is the solution:
In a gateway plugin we don't need to refresh all the cache partitions. Instead, we need to refresh only resource cache of all domains pointing to
web context because its much more faster:
$modx->cacheManager->refresh(array(
'context_settings' => array('contexts' => $contexts),
'resource' => array('contexts' => array_diff($contexts, array('mgr')))
), $results);
After that, install the
microcache plugin by opengeek via Plugin Manager:
http://modx.com/extras/package/microcache
And finally, comment out those lines in microcache plugin itself for plugin to work on your main content:
/* do not cache if the cacheable content still contains unprocessed tags */
//$matches = array();
//if ((($isAnonymous && !empty($skipIfTagsRemainAnonymous)) || (!$isAnonymous && !empty($skipIfTagsRemain))) && $modx->parser->collectElementTags($modx->resource->_content, $matches)) break;
Now everything is smooth and shiny. 4 partially different sites in one context + 1 different language site on another context working fast without any bugs.