On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • In an attempt to make a "clear cache" option that works consistently, I looked up some PHP that simply deletes everything in a folder, and told it to delete everything in the core/cache folder (effectively mimicking a manual clear you'd do through cPanel or FTP).

    <?php
    $dir = "/host/site/core/cache";
    $di = new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS);
    $ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST);
    foreach ( $ri as $file ) {
        $file->isDir() ?  rmdir($file) : unlink($file);
    }
    return "Cache cleared.";
    ?>

    (I've moved the core folder outside public_html, so the path is correct.)

    If I put the PHP in a file and access it directly at www.site.com/clearcache.php, it works fine, and the core/cache folder is empty until a page or the manager is loaded.

    To make it more accessible I:
    - put the contents inside core/components/clearcache/index.php file
    - created a new Namespace called "clearcache" with a Core path of "{core_path}components/clearcache/"
    - created a new Top Menu item with an Action of "index" and a Namespace of "clearcache"

    When I click on the new menu item, it returns "Cache cleared", however, the core/cache folder isn't empty. Is this because clicking on the menu item and loading the new page actively caches new content, or is there something in my PHP Modx doesn't like?

    I'm running:
    Modx Revolution 2.5.2-pl
    PHP 5.5.38
    • Or you could install the CacheClear extra, which does the same thing wink

      And yes, the cache is refreshed when there's a new request.


        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
      • Thanks for the extra! I'll definitely use that instead.

        Thanks for the info, too.