Have a look at that: https://github.com/modxcms/revolution/pull/428This is a partial solution. It does not account for the fact that the caching configuration could be different per Context. And with some additional logic, this could be the solution for 2.3.x.
I use it in one of my installations (though it's a core modification which should be incorporated in my eyes) and it works...maybe that would also solve your problem?
No, because Resources can be forwarded to across Contexts, or (a rarely used feature) even exist in multiple Contexts.
That sounds great, would love to see that (even extended...) in 2.3.x!It's not a stupid question; it's actually a hidden feature.
Quote from: opengeek at Dec 10, 2012, 06:55 PMNo, because Resources can be forwarded to across Contexts, or (a rarely used feature) even exist in multiple Contexts.
regarding to the statement "even exist in multiple contexts", how is that ment ie. how can I have resource (the same one??) in multiple contexts? (sry for the maybe stupid question =D)
web
resource name (1) // -> original resource with id = 1
resource name (2)
context 2
resource name (1*) // -> reference to resource with id = 1 and * as identifier for a "cloned" (not actually...just didn't find a better word =D) resource
resource name (3)
$ck = $resource->getCacheKey();
$mgrCtx = $modx->context->get('key');
$cKey = str_replace($mgrCtx, $ctx, $ck);
// my_debug('CK: ' . $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 */
$ctxResources = $modx->getCollection('modContextResource', array('resource' => $docId));
if (!empty ($ctxResources)) {
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))
)
);
}
}$ck = $modx->resource->getCacheKey(); // web/resources/xxx
$modx->cacheManager->delete($ck, 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))
)
);$ck = $modx->resource->getCacheKey();
$path = MODX_CORE_PATH . 'cache/resource/' . $ck . '.cache.php';
if ($path && file_exists($path)) {
unlink($path);
}
If I simplify a bit this code to this (just one context):I just tested this code and the individual Resource cache files were deleted as expected. I also tested using other cache handlers (APC + memcache) and these worked as well.
$ck = $modx->resource->getCacheKey(); // web/resources/xxx $modx->cacheManager->delete($ck, 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)) ) );
It does nothing, doesnt clear cache
We don't do that because that will only work when the cache_handler is configured as xPDOFileCache. Change it to another class, and attempting to remove cache files like that will not work.
Why dont we just delete those bloody files using this?:
$ck = $modx->resource->getCacheKey(); $path = MODX_CORE_PATH . 'cache/resource/' . $ck . '.cache.php'; if ($path && file_exists($path)) { unlink($path); }
$ck = MODX_CORE_PATH . "cache/resource/" . $modx->resource->getCacheKey();