WebsiteBaker Community Forum

WebsiteBaker Support (2.10.x) => General Help & Support => Topic started by: johnbroeckaert on February 07, 2018, 08:17:53 AM

Title: cache wb site on server?
Post by: johnbroeckaert on February 07, 2018, 08:17:53 AM
Hi all,

I try to use the smartest way to make a site cache on the server. I know there is a cache script that requires me to change something in the index.php, but I can not find that script in the forum anymore. @evaki recently published a kind of cache that stood in the 'sandbox' with them. Is it still up-to-date?
I found the code below at METRICS. Is that just usable in a .htaccess file?

Code: [Select]
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 2 days"
</IfModule>
## EXPIRES CACHING ##

What would be the smartes way?
Thanks
Title: Re: cache wb site on server?
Post by: evaki on February 07, 2018, 09:44:20 AM
Hi,
"Sandkasten" 08.Jan.2018 - One of ???
Source without control structures (on/off)
I don't know if any of this is working, (experimental status)
Code: [Select]
<?php
//"Sandkasten" 08.Jan.2018
//Template cache for static files
$url $_SERVER["SCRIPT_NAME"];
$break Explode('/'$url);
$file $break[count($break) - 1];
//$cachefile =$_SERVER['DOCUMENT_ROOT'].PAGES_DIRECTORY.'/'. 'iscached-'.substr_replace($file ,"",-4).'.html';
$cachefile =$_SERVER['DOCUMENT_ROOT'].PAGES_DIRECTORY.'/'''.substr_replace($file ,"",-4).'.html';
//$cachefile =$_SERVER['DOCUMENT_ROOT'].'/'. 'iscached-'.substr_replace($file ,"",-4).'.html';
//$cachefile =$_SERVER['DOCUMENT_ROOT'].'/'. ''.substr_replace($file ,"",-4).'.htm';

$cachetime 18000;
// Serve from the cache if it is younger than $cachetime
if (file_exists($cachefile) && time() - $cachetime filemtime($cachefile)) {
    echo 
"<!-- Cached copy, generated ".date('H:i'filemtime($cachefile))." -->\n";
    include(
$cachefile);
    exit;
}
ob_start();
?>

<html>
<body>
..............................
</body>
</html>
<?php
$fp 
fopen($cachefile'w');
fwrite($fpob_get_contents());
fclose($fp);
ob_end_flush();  
?>

Example: CMS in root/cms static file in root
MfG. Evaki
Title: Re: cache wb site on server?
Post by: johnbroeckaert on February 07, 2018, 10:16:37 AM
@evaki
Thanks.
I wiil test your code today.
I guess turning it off is just remove the code from the template?
Do you by any chance know the METRICS script witch goes in the .htaccces file?
Title: Re: cache wb site on server?
Post by: evaki on February 07, 2018, 10:30:57 AM
Hi.
>>I guess turning it off is just remove the code from the template?
Yes,
but the generated static files have to be deleted manually. (FTP)
>>...know the METRICS script
No

............Am gone again -work
MfG. Evaki
Title: Re: cache wb site on server?
Post by: Gast on February 07, 2018, 10:37:30 AM
i use this solution here for a while, works for me without problems

https://forum.WebsiteBaker.org/index.php/topic,28202.msg203218.html#msg203218
Title: Re: cache wb site on server?
Post by: evaki on February 07, 2018, 11:01:07 AM
Jo. isn -wenn man so will- Mix (Idee) aus der "ganz alten" und der "neuen" vorgestellten Version. Jedenfalls kann er ein wenig experimentieren. Vielleicht reicht ja das ein oder andere.

Wer mehr will, muß halt "richtige" Kontrollstrukturen einbauen, was einen nicht unerheblichen Mehraufwand mit sich bringt, und je nach CMS, heutzutage nicht mehr so leicht "wie früher" umzusetzen ist. (Hab' mal ein wenig in einigen reingeschaut)
MfG. Evaki
Title: Re: cache wb site on server?
Post by: johnbroeckaert on February 07, 2018, 11:21:13 AM
Thank you both @jacobi22 and @evaki.

I'm testing  :-D