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