We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37912
    • 12 Posts
    I'm trying to clear the resource cache for a specific context, but no matter what I do, it always clears all contexts.

    The Code:
    $coreConfig = dirname(dirname(dirname(__FILE__))) . '/config.core.php';
    
    require_once $coreConfig;
    require_once MODX_CORE_PATH.'config/'.MODX_CONFIG_KEY.'.inc.php';
    
    require_once MODX_CORE_PATH.'model/modx/modx.class.php';
    
    $modx = new MODx();
    $modx->initialize('site1');
    
    $results = array();
    $modx->cacheManager->refresh(array(
        'resource' => array('contexts' => array('site1'))
    ), $results);
    


    I feel like I'm missing something really obvious...
      • 22303 MODX Staff
      • 10,725 Posts
      First, do not include the config file manually; this line is not necessary:
      require_once MODX_CORE_PATH.'config/'.MODX_CONFIG_KEY.'.inc.php';


      Second, are you using the default file-based cache handler?
        • 37912
        • 12 Posts
        So, a little bit of background:

        I'm testing an approach where users make changes on one MODx install, and MySQL replicates the data to another MODx install where visitors will actually view the site.

        This code is a (dirty) prototype of a service that the management install will call to clear the cache on the "live" install. This code is currently just sitting in /html/assets/components/, and is being called via cURL.

        That's why I'm manually including the config file.

        And, yes, I'm using the default, file-based cache handler.
          • 37912
          • 12 Posts
          I was over-thinking things a little. I created a resource (I'm in Revo 2.2.4), and a snippet.

          $modx->cacheManager->refresh(array(
              'resource' => array('contexts' => array('site1'))
          ));


          That's all the code. It's still clearing the resource cache for all of the contexts ("web" and "site1").

          Thanks for your help,

          Tony