Page 1 of 1
Caching entire site
Posted: Fri Nov 18, 2005 4:50 pm
by carlos
Hi.
I have a site with CMSMS. I don't need generate dynamic contend (this site not change every day).
¿Its possible to "tweak" smarty templates to cache all pages and only regenerate it when I made the changes?
Re: Caching entire site
Posted: Fri Nov 18, 2005 6:11 pm
by Piratos
This is the standard configured as in content.functions.php
Code: Select all
$this->caching = true;
$this->compile_check = true;
$this->assign('app_name','CMS');
$this->debugging = false;
$this->force_compile = false;
$this->cache_plugins = false;
Re: Caching entire site
Posted: Fri Nov 18, 2005 9:47 pm
by fadum
I have a few additions to the CMSMS script that generates a cache of the complete page on first visit, it will then use this cache.
When you next login to admin it deletes the cached pages and starts again.
Result = Very Fast pages and no Mysql use on cached pages
If anyones interested in it let me know
Re: Caching entire site
Posted: Thu Nov 24, 2005 9:24 am
by roman
hi, apart of this thread i created yesterday hack for caching static pages. without smarty functions how set piratos, i don't know about them by now. in future can by for this admin part, for swith pages whitch don't will be cachce. for example page with news, forms... this hack is not secured against something, need some changes (probably)
just put following code into start of index.php file, after copyright informations:
Code: Select all
$starttime = microtime();
#### SUPER CACHE START ##### author of idea roman hanajik
# this is only for real static pages ...not pages with something like forms
$supercache = false;
if (file_exists('tmp/super/_index.html')){
$supercachedir = 'tmp/super/'; // your cache directory, must containt file "_index.html" and must be writable
//echo "use super cache part I";
$supercache = true;
// here must be security isue against walking on the web directories?, and maybe later code for including into code also other variables from url
$page = $page;
// if $page dasn't exist, we must find default page, later this can call specific file in tmp/super/directory/, for example index.html :)
if ($page == ""){
$pagename = 'index';
}else{
$pagename = $page;
}
if (file_exists($supercachedir . $pagename)){
require($supercachedir . $pagename);
/**/
$endtime = microtime();
$diff = number_format(((substr($endtime,0,9)) + (substr($endtime,-10)) - (substr($starttime,0,9)) - (substr($starttime,-10))),4);
echo "<br><br><small>Generated with CMS Made Simple in $diff s. using super cachce.</small>";
/**/
echo "<time start: $starttime time stop: ",microtime();
die;
}else{ // else nothing ... cms will run normall and content will by generated and maybe written into super cahce dir
$pagenot = true;
}
}
#### SUPER CACHE STOP PART I #####
and following code into end of index.php file:
Code: Select all
#### SUPER CACHE START PART II #####
if ($supercache and $pagenot){ // write page to super cahce dir and put into db
$handle = fopen ($supercachedir . $pagename, "w");
//echo " pagename: $pagename handle:",$handle;
$html .= "<!-- Generated by CMS Made Simple (super cached by roman) -->\n";
$html .= "<!-- CMS Made Simple - Released under the GPL - http://cmsmadesimple.org -->\n";
fputs($handle, $html);
fclose($handle);
}
#### SUPER CACHE STOP PART II #####
and create in tmp dir directory named super ...

, (
set privilegies for writing .... and enjoy
part about writing microtime into html you can remove, but you will see ~50 times faster script against to normal sql generating page
Re: Caching entire site
Posted: Thu Nov 24, 2005 12:22 pm
by roman
also impement this into stylesheet.php ...
Re: Caching entire site
Posted: Tue Dec 06, 2005 1:07 pm
by roman
And if you like to after editing content of page delete old cache, open file admin-editcontent.php and ~line 121, after:
and before:
Code: Select all
#Fill contentobj with parameters
$contentobj->FillParams($_POST);
$error = $contentobj->ValidateData();
put this code:
Code: Select all
#If exist super cache delete old content of just sended file
if (file_exists('../tmp/super/_index.html')){
$cachefile = '../tmp/super/' . $_POST['alias'];
if (file_exists($cachefile)){
unlink('../tmp/super/' . $_POST['alias']);
}
}
Re: Caching entire site
Posted: Tue Dec 06, 2005 1:26 pm
by Ted
If you want this to be more automatic, you can also check the timestamp of the last time content was updated. This will only work with 0.11+, though. But, it should require less code modification on your side...
Code: Select all
global $gCms;
$pageinfo =& $gCms->variables['pageinfo'];
$time = $pageinfo->content_last_modified_date;