$z = $modx->getCacheManager(); $resource = $modx->getObject('modResource',1); $results = $z->generateResource($resource);
This question has been answered by multiple community members. See the first response.
Hey,
did you get it to work? Can you tell me what was the best way for you!?
$modx->setLogLevel(modX::LOG_LEVEL_DEBUG); $HTpages = $modx->getCollection('modResource'); $modx->getCacheManager(); foreach($HTpages as $page) { $results = $modx->cacheManager->generateResource($page); } $modx->log(modX::LOG_LEVEL_DEBUG, 'We wrote some cache files!!!');
//Modx original code. This fails: if (is_object($obj) && $obj instanceof modResource && $obj->getProcessed() && $obj->get('cacheable') && $obj->get('id')) { //Modified code. This works (kindof): if (is_object($obj) && $obj instanceof modResource /*&& $obj->getProcessed()*/ && $obj->get('cacheable') && $obj->get('id')) {
'_content' => ' This is the time (cached): Thursday 17th of November 2011 12:04:30 PM This is the time (UNcached): [[!test time]] ',
'_content' => '',
/* invoke OnSiteRefresh event */ $modx->invokeEvent('OnSiteRefresh');
<?php include_once('/a/server/path/phpClasses/generateCacheFiles.php');
$page->process(); $results = $modx->cacheManager->generateResource($page);
Thank you for the great answer!
I got the same problem, that it is not working in the plugin. In the snippet, it is kind of working....
Possible solutions:
Issue 1: If you process the resource before generating it. Shouldn't this solve this issue?
$page->process(); $results = $modx->cacheManager->generateResource($page);
[[test time?]] This is a timestamp (Cached) [[!test time]] This is a timestamp (UNcached)
Sunday 20th of November 2011 09:30:29 AM This is a timestamp (Cached) [[!test time]] This is a timestamp (UNcached)
if (!empty($scriptProperties['syncsite']) || !empty($scriptProperties['clearCache'])) { /* empty cache */ $modx->cacheManager->refresh(array( 'db' => array(), 'auto_publish' => array('contexts' => array($resource->get('context_key'))), 'context_settings' => array('contexts' => array($resource->get('context_key'))), 'resource' => array('contexts' => array($resource->get('context_key'))), )); /* I could see the if statement was occurring because of this log statement... */ $modx->log(modX::LOG_LEVEL_DEBUG, 'The site refresh happened.'); /* But I had to add invokeEvent to get plug-in to fire... */ $modx->invokeEvent('OnSiteRefresh'); }
if (!empty($scriptProperties['syncsite']) || !empty($scriptProperties['clearCache'])) { /* empty cache */ $modx->cacheManager->refresh(array( 'db' => array(), 'auto_publish' => array('contexts' => array($resource->get('context_key'))), 'context_settings' => array('contexts' => array($resource->get('context_key'))), 'resource' => array('contexts' => array($resource->get('context_key'))), )); /* confirm refresh happened: */ $modx->setLogLevel(modX::LOG_LEVEL_DEBUG); $modx->log(modX::LOG_LEVEL_DEBUG, 'The refresh happened.'); }
<?php /* confirm plugin fired: */ $modx->setLogLevel(modX::LOG_LEVEL_DEBUG); $modx->log(modX::LOG_LEVEL_DEBUG, 'The plugin fired.');
[2011-11-20 23:03:07] (DEBUG @ /modxRevo/connectors/resource/index.php) The refresh happened.