We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40387
    • 28 Posts
    this makes MODx delete all resources:

    $resource = $modx->getObject('modResource', $id);
    $paths = array('');
    $options = array('object' => $resource);
    $modx->cacheManager->clearCache($paths, $options);
      • 3749
      • 24,544 Posts
      If you're using the default caching system in MODX, this will usually do it:

      $ctx = $resource->get('context_key');
      $docId = $resource->get('id');
      
      // $path = MODX_CORE_PATH . 'cache/resource/' . $ctx . '/resources/' . $docId . '.cache.php';
      unlink($path);
      


      This is a more generic solution that should work regardless of the caching scheme:

      $ctx = $resource->get('context_key');
      $docId = $resource->get('id');
      
      /* set path to default cache file */
      $path = MODX_CORE_PATH . 'cache/resource/' . $ctx . '/resources/' . $docId . '.cache.php';
      $ck = $resource->getCacheKey();
      
      /* These two lines are only needed if in a plugin that runs in the Manager */
      // $mgrCtx = $modx->context->get('key');
      // $cKey = str_replace($mgrCtx, $ctx, $ck);
      
      $modx->cacheManager->delete($cKey, array(
          xPDO::OPT_CACHE_KEY => $modx->getOption('cache_resource_key', null, 'resource'),
          xPDO::OPT_CACHE_HANDLER => $modx->getOption('cache_resource_handler', null,
          $modx->getOption(xPDO::OPT_CACHE_HANDLER)),
          xPDO::OPT_CACHE_FORMAT => (integer)$modx->getOption('cache_resource_format', null,
          $modx->getOption(xPDO::OPT_CACHE_FORMAT, null, xPDOCacheManager::CACHE_PHP)))
      );
      
      
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 40387
        • 28 Posts
        Thanks again Bob,

        Quote from: BobRay at Nov 05, 2013, 03:46 PM
        If you're using the default caching system in MODX, this will usually do it:

        $ctx = $resource->get('context_key');
        $docId = $resource->get('id');
        
        // $path = MODX_CORE_PATH . 'cache/resource/' . $ctx . '/resources/' . $docId . '.cache.php';
        unlink($path);
        


        This is a more generic solution that should work regardless of the caching scheme:

        $ctx = $resource->get('context_key');
        $docId = $resource->get('id');
        
        /* set path to default cache file */
        $path = MODX_CORE_PATH . 'cache/resource/' . $ctx . '/resources/' . $docId . '.cache.php';
        $ck = $resource->getCacheKey();
        
        /* These two lines are only needed if in a plugin that runs in the Manager */
        // $mgrCtx = $modx->context->get('key');
        // $cKey = str_replace($mgrCtx, $ctx, $ck);
        
        $modx->cacheManager->delete($cKey, array(
            xPDO::OPT_CACHE_KEY => $modx->getOption('cache_resource_key', null, 'resource'),
            xPDO::OPT_CACHE_HANDLER => $modx->getOption('cache_resource_handler', null,
            $modx->getOption(xPDO::OPT_CACHE_HANDLER)),
            xPDO::OPT_CACHE_FORMAT => (integer)$modx->getOption('cache_resource_format', null,
            $modx->getOption(xPDO::OPT_CACHE_FORMAT, null, xPDOCacheManager::CACHE_PHP)))
        );
        
        
          • 40387
          • 28 Posts
          taking advantage of the "hook", you could tell me if it is possible to open the "MODx filebrowser" in frontend?
            • 3749
            • 24,544 Posts
            Anything is possible, but I don't think there's any easy way to do it.
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting