$resource = $modx->getObject('modResource', $id);
$paths = array('');
$options = array('object' => $resource);
$modx->cacheManager->clearCache($paths, $options);
$ctx = $resource->get('context_key');
$docId = $resource->get('id');
// $path = MODX_CORE_PATH . 'cache/resource/' . $ctx . '/resources/' . $docId . '.cache.php';
unlink($path);
$ctx = $resource->get('context_key');
$docId = $resource->get('id');
/* set path to default cache file */
$path = MODX_CORE_PATH . 'cache/resource/' . $ctx . '/resources/' . $docId . '.cache.php';
$ck = $resource->getCacheKey();
/* These two lines are only needed if in a plugin that runs in the Manager */
// $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)))
);
If you're using the default caching system in MODX, this will usually do it:
$ctx = $resource->get('context_key'); $docId = $resource->get('id'); // $path = MODX_CORE_PATH . 'cache/resource/' . $ctx . '/resources/' . $docId . '.cache.php'; unlink($path);
This is a more generic solution that should work regardless of the caching scheme:
$ctx = $resource->get('context_key'); $docId = $resource->get('id'); /* set path to default cache file */ $path = MODX_CORE_PATH . 'cache/resource/' . $ctx . '/resources/' . $docId . '.cache.php'; $ck = $resource->getCacheKey(); /* These two lines are only needed if in a plugin that runs in the Manager */ // $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))) );