Skip to content

Instantly share code, notes, and snippets.

@opengeek
Created March 26, 2012 22:43
Show Gist options
  • Save opengeek/2210354 to your computer and use it in GitHub Desktop.
Save opengeek/2210354 to your computer and use it in GitHub Desktop.
Example of how to cache static HTML copies of MODX Resources using plugin + mod_rewrite
# Add this before your MODX Friendly URLs RewriteCond's and RewriteRule...
RewriteCond /abs/path/to/docroot/statcache%{REQUEST_URI} -f
RewriteRule ^(.*)$ /statcache/$1 [L,QSA]
<?php
switch ($modx->event->name) {
case 'OnBeforeSaveWebPageCache':
if ($modx->resource->_output != '') {
$statcacheFile = $modx->getOption('statcache_path', $scriptProperties, MODX_BASE_PATH . 'statcache/') . $modx->makeUrl($modx->resource->get('id'));
if (!$modx->cacheManager->writeFile($statcacheFile, $modx->resource->_output)) {
$modx->log(modX::LOG_LEVEL_ERROR, "Error caching output from Resource {$modx->resource->get('id')} to static file {$statcacheFile}", '', __FUNCTION__, __FILE__, __LINE__);
}
}
break;
}
@antsplace
Copy link

Could you please explain how one would go about getting this to work - please :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment