Thought I would update this thread in case anyone was interested.
Issue:
"generateReource()" not writing cache files when executed via plug-in (but works fine in a snippet).
Resolution:
Add the line: "$resource->_contextKey = $resource->get('context_key');"
Insert it before: "$modx->cacheManager->generateResource($resource);"
Issue:
When writing multiple cache files, "generateResource()" writes mismatched content into the "_content" portion of the cache file.
If a snippet (ID1) executes "generateResource(ID3)" and "generateResource(ID5)", the "_content" in both "3.cache.php" and "5.cache.php" is for ID1.
If a plug-in executes "generateResource()" for ID3 and ID5, the "_content" in "5.cache.php" will contain the content for ID3.
Sample code:
<?php
$modx->setLogLevel(modX::LOG_LEVEL_DEBUG);
$modx->log(modX::LOG_LEVEL_DEBUG, 'Write some cache files');
// Get all published page resources:
$matches = $modx->getCollection('modResource',array(
'published' => 1
));
// Generate cache files for each resource
$modx->getCacheManager();
foreach($matches as $match) {
$match->process();
//Next line is for plugin:
$match->_contextKey = $match->get('context_key');
$modx->cacheManager->generateResource($match);
$modx->log(modX::LOG_LEVEL_DEBUG, '>>>Cache created for: '.$match->get('id'));
}