Skip to content

Instantly share code, notes, and snippets.

@gibbs
Created October 27, 2013 13:44
Show Gist options
  • Save gibbs/7182293 to your computer and use it in GitHub Desktop.
Save gibbs/7182293 to your computer and use it in GitHub Desktop.
Refresh / clear the MODx Revolution (2.0.*) cache
<?php
/*
* Clear (refresh) MODx Cache from external PHP Script
*
* MODx Revolution (2.0.7-pl)
* Daniel Gibbs
*/
// Path to MODx Core Directory
define("MODX_CORE_PATH", "../core/");
define("MODX_CONFIG_KEY", "config");
// Include MODx main class
include(MODX_CORE_PATH."model/modx/modx.class.php");
// Instantiate
$modx= new modX();
$modx->initialize("xPDO");
// Clear the cache (taken from /core/model/modx/processors/system/clearcache.php)
$paths = array(
'config.cache.php',
'sitePublishing.idx.php',
'registry/mgr/workspace/',
'lexicon/',
);
$contexts = $modx->getCollection('modContext');
foreach ($contexts as $context) {
$paths[] = $context->get('key') . '/';
}
$options = array(
'publishing' => 1,
'extensions' => array('.cache.php', '.msg.php', '.tpl.php'),
);
if ($modx->getOption('cache_db')) $options['objects'] = '*';
// The final magic
$results= $modx->cacheManager->clearCache($paths, $options);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment