Created
March 26, 2012 22:43
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could you please explain how one would go about getting this to work - please :)