WebsiteBaker 2.13.8 is now available!
R.I.P Dietmar (luisehahne) and thank you for all your valuable work for WBhttps://forum.websitebaker.org/index.php/topic,32355.0.html
<?php $nonCached = array('314','555'); // pages not to be cached (contact, news etc.) foreach($nonCached as $nonCachedPage) { if(PAGE_ID == $nonCachedPage) { } else { $cachefile = WB_PATH.'/storage/'.sha1(PAGE_TITLE.'-'.PAGE_ID); $cachetime = 30 * 60; // 30 minutes// $cachetime = 0; // disable cache if (file_exists($cachefile) && (time() - $cachetime < filemtime($cachefile))) { echo "<!-- Cached by REVAMDS Page Cache at ".date('jS F Y H:i', filemtime($cachefile))." -->"; include($cachefile); exit; } } } ?>
<?php foreach($nonCached as $nonCachedPage) { if(PAGE_ID == $nonCachedPage){ echo $output; exit; die; } } if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start(); echo $output; $fp = fopen($cachefile, 'w'); fwrite($fp, ob_get_contents()); fclose($fp); ob_end_flush();?>
require(WB_PATH.'/storage/start.php');
require(WB_PATH.'/storage/stop.php');
<?php // create a cachefile id. Must be done first to supress errors in stop.php $key = PAGE_TITLE.'-'.PAGE_ID; if(isset($post_id)) $key .= $post_id; // add id of newspage if(isset($item_id)) $key .= $item_id; // add id of bakery page $cachefile = WB_PATH.'/storage/'.sha1($key); // set noncachable pages $nonCached = array(123,456); // page id's not to be cached // return from this script is page should not be cached.. foreach($nonCached as $nonCachedPage) { if(PAGE_ID == $nonCachedPage) return; } if($_SERVER['REQUEST_METHOD'] == 'POST' ) return; // forms should not be cached if(isset($_GET['_wb'])) unset($_GET['_wb']); // fix if shorturl is used if(count($_GET)) return; // like in forms, "pervious/next" and search pages // use the cache if it is available and not too old $cachetime = 30 * 60; // 30 minutes if (file_exists($cachefile) && (time() - $cachetime < filemtime($cachefile))) { include($cachefile); echo "<!-- Cached by REVAMDS Page Cache at ".date('jS F Y H:i', filemtime($cachefile))." -->"; exit; }?>
The speed is very nice, but there are some issues..- The foreach in start.php does not function. If the page is not the first one in the $nonCached array, it will become a cachable page. The second one is never tested.- Any page request with parameters ($_GET or $_POST) should not be cached. (except when using shorturl)- News and Bakery pages can be detected. No need to put them in the nonCached array manually.- The inserted cache comment at the top could break correct browser rendering (IE could go into quirks mode)A modified start.php below fixes these issues:Code: (more testing needed) [Select]<?php // create a cachefile id. Must be done first to supress errors in stop.php $key = PAGE_TITLE.'-'.PAGE_ID; if(isset($post_id)) $key .= $post_id; // add id of newspage if(isset($item_id)) $key .= $item_id; // add id of bakery page $cachefile = WB_PATH.'/storage/'.sha1($key); // set noncachable pages $nonCached = array(123,456); // page id's not to be cached // return from this script is page should not be cached.. foreach($nonCached as $nonCachedPage) { if(PAGE_ID == $nonCachedPage) return; } if($_SERVER['REQUEST_METHOD'] == 'POST' ) return; // forms should not be cached if(isset($_GET['_wb'])) unset($_GET['_wb']); // fix if shorturl is used if(count($_GET)) return; // like in forms, "pervious/next" and search pages // use the cache if it is available and not too old $cachetime = 30 * 60; // 30 minutes if (file_exists($cachefile) && (time() - $cachetime < filemtime($cachefile))) { include($cachefile); echo "<!-- Cached by REVAMDS Page Cache at ".date('jS F Y H:i', filemtime($cachefile))." -->"; exit; }?>Cheers,Ruud
You could try a lot more by analizing the html (like any <form> tag in the page should not cache).
This was easy to implement WinkThe current attached version will not cache any page that looks like a form.
<?php // when set, generation timing will be displayed. $debug_cache = true;
if(!stripos($output,'<form') === false) $donotCache = true;if(!stripos($output,'<input') === false) $donotCache = true;
works fine and code looks clean, but the 'checking' is to tight with this linesand as I see it it's better to comment em out:
if(!stripos($output,'class="frm-nixhier"') === false) $donotCache = true;if(!stripos($output,'name="captcha"') === false) $donotCache = true;
<!-- Cached by REVAMDS Page Cache at ".date('jS F Y H:i', filemtime($cachefile))." -->
Plan is to make this automatically when Login ....Anyone free to collaborate with me to this?
if($wb->is_authenticated()) return;
if($wb->is_authenticated() && file_exists($cachefile)) unlink($cachefile);