Hello,
I’m creating a whole bunch of MODx documents in my own PHP programm - and calling clearCache() at the end - but when I look at the site, the new documents are not visible yet in the menu.
If I then do a clear cache in the MODx manager and look again at the site - yes, there they are...
It’s not a huge problem, because I can do a clear cache in the manager each time I added documents, but I would prefer to do everything that needs to be done from my code of course.
So the question is: is there a difference between the two forms of clearCache - and is there a way to accomplish the same thing from PHP code?
The code in the clearcache processor(/core/model/modx/processors/system/clearcache.php) does it like this :-
$contexts = $modx->getCollection('modContext');
foreach ($contexts as $context) {
$paths[] = $context->get('key') . '/';
}
$options = array(
'publishing' => 1,
'extensions' => array('.cache.php', '.msg.php', '.tpl.php'),
);
if ($modx->getOption('cache_db')) $options['objects'] = '*';
$results= $modx->cacheManager->clearCache($paths, $options);
i.e it clears for each context.
If you want to ’see’ the changes to might have to force a page(resource tree maybe) refresh after this.
Use MODx, or the cat gets it!
Thanks, that seems to solve the issue!
-
MODX Staff
- 10,725 Posts
FWIW, you can call the actual core processor (and respect permissions you apply to the context you are running this in) by using the $modx->executeProcessor() method.
Ah, I was thinking of recommending doing that but I didn’t know that method existed, wouldn’t that try and draw the console window output though and what do you do with the JSON encoded success/error return?
Use MODx, or the cat gets it!
JSON-based error-handling is enabled via the connectors.
, how do you do this? A lot of the processors of the getnodes variety seem to return results as JSON encoded by calling the $this->toJSON on the return array, ready for consumption by the manager javascript, although its not clear why anyone would need to do this from snippets etc. I guess some proccessors are more useful than others to just execute.
Use MODx, or the cat gets it!
Yes, they are specialised as you say, the ability to do this at all gives you an ’extra’ API above the MODx class API. I can see this ability being quite useful even if the results are in JSON sometimes.
Use MODx, or the cat gets it!