We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3496
    • 101 Posts
    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?
      • 26903
      • 1,336 Posts
      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!
        • 3496
        • 101 Posts
        Thanks, that seems to solve the issue!
          • 22303 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.
            • 26903
            • 1,336 Posts
            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!
              • 3496
              • 101 Posts
              Thanks Jason.
                • 22303 MODX Staff
                • 10,725 Posts
                Quote from: shamblett at Jun 30, 2010, 12:05 PM

                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?
                Nope, the output is abstracted and only returned via JSON when the JSON-based error-handling is enabled via the connectors. Using the method allows you to execute them as if they were directly accessible functions, returning results that can easily be handled directly in PHP. Just be aware that you will have to apply appropriate policies to the web (or other contexts) you want the processors to be executable in or you may leave the possibility open for a manager user to execute processors arbitrarily via Snippets. IOW, don’t give anonymous users (or members of inappropriate User Groups) the Administrator policy in the web context.
                  • 26903
                  • 1,336 Posts
                  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!
                    • 22303 MODX Staff
                    • 10,725 Posts
                    Quote from: shamblett at Jun 30, 2010, 03:20 PM

                    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.
                    Hmm, in those cases, you can simply take the response and $modx->fromJSON() it to make use of it? I think that is only specialized processors for some of the UI widgets, no?
                      • 26903
                      • 1,336 Posts
                      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!