Author Topic: cache wb site on server?  (Read 579 times)

Offline johnbroeckaert

  • Posts: 186
  • Gender: Male
cache wb site on server?
« 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
It is a happy talent to know how to play!

Offline evaki

  • Posts: 2695
Re: cache wb site on server?
« Reply #1 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
« Last Edit: February 07, 2018, 09:53:29 AM by evaki »
Einmal Pizza Quattro Stagioni bitte, aber ohne Herbst.

Offline johnbroeckaert

  • Posts: 186
  • Gender: Male
Re: cache wb site on server?
« Reply #2 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?
It is a happy talent to know how to play!

Offline evaki

  • Posts: 2695
Re: cache wb site on server?
« Reply #3 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
Einmal Pizza Quattro Stagioni bitte, aber ohne Herbst.

Offline jacobi22

  • Posts: 5843
  • Gender: Male
  • Support also via PM or EMail
    • Jacobi22
Re: cache wb site on server?
« Reply #4 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
Wer nicht will, findet Gründe, wer will, findet Wege.

Offline evaki

  • Posts: 2695
Re: cache wb site on server?
« Reply #5 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
Einmal Pizza Quattro Stagioni bitte, aber ohne Herbst.

Offline johnbroeckaert

  • Posts: 186
  • Gender: Male
Re: cache wb site on server?
« Reply #6 on: February 07, 2018, 11:21:13 AM »
Thank you both @jacobi22 and @evaki.

I'm testing  :-D
It is a happy talent to know how to play!

 

postern-length