Skip to content

Instantly share code, notes, and snippets.

@pepebe
Created February 27, 2012 14:22
Show Gist options
  • Save pepebe/1924151 to your computer and use it in GitHub Desktop.
Save pepebe/1924151 to your computer and use it in GitHub Desktop.
MODx: REFRESH / CLEAR MODX (REVOLUTION) CACHE FROM PHP SCRIPT REFRESH / CLEAR MODX (REVOLUTION) CACHE FROM PHP SCRIPT
<?php
/* Downloaded from: http://www.dangibbs.co.uk/journal/clear-modx-revolution-cache-from-php-script
UNTESTED!!!
*/
/*
* 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