@lettis There is also a copy in core/cache/includes/elements/modsnippet, and yes I think there is a problem with keeping MODX from clearing the whole site cache when you save a snippet, but I can't remember for sure. This is also the case with templates.
@donshakespeare Yes, cache_scripts only affects snippets and plugins. Templates aren't cached in the first place (nor are TVs).
Just deleting the cache file is fine unless you want to distribute your code. In that case you don't know what cache scheme is being used and you end up with something ugly and difficult to read like this:
$ck = $resource->getCacheKey();
$mgrCtx = $modx->context->get('key');
$cKey = str_replace($mgrCtx, $ctx, $ck);
$modx->cacheManager->delete($cKey, array(
xPDO::OPT_CACHE_KEY => $modx->getOption('cache_resource_key', null, 'resource'),
xPDO::OPT_CACHE_HANDLER => $modx->getOption('cache_resource_handler', null,
$modx->getOption(xPDO::OPT_CACHE_HANDLER)),
xPDO::OPT_CACHE_FORMAT => (integer)$modx->getOption('cache_resource_format', null,
$modx->getOption(xPDO::OPT_CACHE_FORMAT, null, xPDOCacheManager::CACHE_PHP))
)
);
/* see if resource exists in any other contexts, and if so, clear those caches too */
$ctxResources = $modx->getCollection('modContextResource', array('resource' => $docId));
foreach ($ctxResources as $ctxResource) {
/* @var $ctxResource modContextResource */
$key = $ctxResource->get('context_key');
$cKey = str_replace($mgrCtx, $key, $ck);
$modx->cacheManager->delete($cKey, array(
xPDO::OPT_CACHE_KEY => $modx->getOption('cache_resource_key', null, 'resource'),
xPDO::OPT_CACHE_HANDLER => $modx->getOption('cache_resource_handler', null,
$modx->getOption(xPDO::OPT_CACHE_HANDLER)),
xPDO::OPT_CACHE_FORMAT => (integer)$modx->getOption('cache_resource_format', null,
$modx->getOption(xPDO::OPT_CACHE_FORMAT, null, xPDOCacheManager::CACHE_PHP))
)
);
}
An $object->clearCache() convenience method would come in really handy. I think I'll put in a feature request.