Topic: Improve CuteNews Performance by Adding Page Caching
Pretty easy to add page caching and it makes a world of difference to your server when hosting cutenews and to your visitors! Open your main index script, say index.php and add this the code to very top before $matches[1] else. Point $matches[1] to wherever you keep comments.txt. The reason we point to comments.txt is to provide a simple means to determine when to refresh the cache copy on the client side. Personally I produce a dummy.txt file whenever a comment or news is added and point to that. But this is sufficent for most cases to get rolling.
<?php
header("Cache-Control: must-revalidate");
header("Pragma: cache");
$if_modified_since = preg_replace('/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE']);
$mtime = filemtime("./cutenews/data/comments.txt");
$gmdate_mod = gmdate('D, d M Y H:i:s', $mtime) . ' GMT';
if ($if_modified_since == $gmdate_mod) {
header("HTTP/1.0 304 Not Modified");
die();
}
header("Last-Modified: $gmdate_mod");
?>
Now we need a simple means to refresh the cache in case of a news post instead of a comment. The easist way to do this is edit $matches[1] at the very bottom where you find:
msg("info","News added", "The news item was successfully added.</br>$unapproved_status_msg");
Add this right below this:
touch("./data/comments.txt");
Now you have a easy and fairly decent page caching setup for cutenews that will boost performance.
