We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 11351
    • 16 Posts
    Hi,

    I would like to know how to delete a particular file only in the cache/web/36.cache.php for example. I have used this so far:
    @$modx->cacheManager->clearCache($paths, $options);  


    But it clear all the files. I would like to delete a certain file. Can you please give me some ideas?

    Regards,
    Nick
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Depending on how you want to do it, a module for manual removal and a plugin for automatic removal.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 11351
        • 16 Posts
        Hi,

        I load modx externaly and each time data is submitted which is at a 10 minute basis I clear the cache in order to load the most recent data. The data is loaded from a snippet I have created. I dont understand your reply, can you make it clearer?

        Thanks
          • 22303 MODX Staff
          • 10,725 Posts
          Wouldn’t it be better to simply have the snippet cache it’s own data for 10 minutes?
          $output = '';
          $cachedOutput = $modx->cacheManager->get('mySnippetOutput');
          if (!empty($cachedOutput)) {
              $output = $cachedOutput;
          } else {
              /* Your snippet logic here to build your output */
              $output = 'hello world!';
              /* Now simply cache your output for 10 minutes */
              $modx->cacheManager->set('mySnippetOutput', $output, 60 * 10);
          }
          return $output;
            • 11351
            • 16 Posts
            Hey,

            Thanks for your answer. It works great smiley
              • 22295
              • 153 Posts
              For the record, you can clear a specific page cache using:
              $modx->cacheManager->clearCache(array($resource->getCacheKey() . ’.cache.php’));

              and sometime you’d want to clear the context cache (which contains the context’s structure):
              $modx->cacheManager->clearCache(array("{$resource->context_key}/context.cache.php"));