What is the best way to override changes to CRM_Core_Config?
I've come up with this function to clear cache, when file paths change.


function cacheoff_civicrm_config(&$config) {

  // 1. Get document root from the server
  // 2. Compare to a set path in the cache
  // If 2. doesn't start with 1., then regenerate cache
  // This means the file path has changed

  $templateDir = $config->customTemplateDir;
  $document_root = $_SERVER['DOCUMENT_ROOT'];

  if (!substr($templateDir, 0, strlen($document_root)) === $document_root) {

    CRM_Core_Error::debug( "Path changed: " . $document_root . " doesn't match " . $templateDir ); 
    CRM_Core_Config::clearDBCache();

  }
  _cacheoff_civix_civicrm_config($config);
}