Cache Pages
Moderator: General Moderators
- tecktalkcm0391
- DevNet Resident
- Posts: 1030
- Joined: Fri May 26, 2006 9:25 am
- Location: Florida
Cache Pages
How can you cache pages? I can't find anything when I google cache pages OR websites
Last edited by tecktalkcm0391 on Sun Jun 18, 2006 12:26 am, edited 2 times in total.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
- tecktalkcm0391
- DevNet Resident
- Posts: 1030
- Joined: Fri May 26, 2006 9:25 am
- Location: Florida
One possible way:
Start the script like this:and end it like this:
Start the script like this:
Code: Select all
ob_start();Code: Select all
$buffer = ob_get_clean();
$hash = md5($buffer);
if(isset($_SERVER['HTTP_IF_NONE_MATCH'])){
if($hash == trim($_SERVER['HTTP_IF_NONE_MATCH'], '"')){
header("HTTP/1.x 304 Not Modified");
header('Etag: "'.$hash.'"');
exit;
}
}
header('Etag: "'.$hash.'"');
ob_start('ob_gzhandler');
print $buffer;- tecktalkcm0391
- DevNet Resident
- Posts: 1030
- Joined: Fri May 26, 2006 9:25 am
- Location: Florida
What is that for? What type?
I can just put the
in an included file right?
cause I already start everypage with ob_start();
and end it with ob_flush();
I can just put the
Code: Select all
$buffer = ob_get_clean();
$hash = md5($buffer);
if(isset($_SERVER['HTTP_IF_NONE_MATCH'])){
if($hash == trim($_SERVER['HTTP_IF_NONE_MATCH'], '"')){
header("HTTP/1.x 304 Not Modified");
header('Etag: "'.$hash.'"');
exit;
}
}
header('Etag: "'.$hash.'"');
ob_start('ob_gzhandler');
print $buffer;cause I already start everypage with ob_start();
and end it with ob_flush();
- tecktalkcm0391
- DevNet Resident
- Posts: 1030
- Joined: Fri May 26, 2006 9:25 am
- Location: Florida
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
A classic example is the use of Smarty template caching.. lets say we have a page that does some pretty intensive processing but the data isn't updated frequently, it wouldn't make sense to have it process the same data over and over each time. Instead, we write to an html file all the output of that processing and display that instead.tecktalkcm0391 wrote:Ok, will do, but what is that browser or dynamic/processing caching?
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
There are several ways to do this, you can set timeouts on your cached versions for instance.. or have a controller decide whether there is new content.bokehman wrote:How would you decide whether to serve the cached version or rebuild?
Code: Select all
if ($smarty->isCached())
{
if ($this->hasNewContent())
{
//do processing
}
}
// load template normallyOk, so really this is just about guessing if the content has changed; no conclusive proof. I'm not saying that is wrong, I'm just trying to clarify the point. So the only way to be certain the page hasn't changed is to test the dynamic parts, is that correct? On the solution above he said to save bandwidth, I understand the server load will be the same though. Often though there is a big mismatch in cpu to connection ratio in favour of the cpu. There certainly is in the case of my server where the connection is the bottleneck so I'm not to bothered wasting a few CPU cycles. Also my solution will save money for those paying for bandwidth.Jcart wrote:There are several ways to do this, you can set timeouts on your cached versions for instance.. or have a controller decide whether there is new content.
Anyway I'm interested in more on server side caching to cut CPU and database load as well.
- tecktalkcm0391
- DevNet Resident
- Posts: 1030
- Joined: Fri May 26, 2006 9:25 am
- Location: Florida
Do you know about....http://www.sysbotz.com/articles/phpcache.htm ? I don't have my own server, but if you do that might help.bokehman wrote:Ok, so really this is just about guessing if the content has changed; no conclusive proof. I'm not saying that is wrong, I'm just trying to clarify the point. So the only way to be certain the page hasn't changed is to test the dynamic parts, is that correct? On the solution above he said to save bandwidth, I understand the server load will be the same though. Often though there is a big mismatch in cpu to connection ratio in favour of the cpu. There certainly is in the case of my server where the connection is the bottleneck so I'm not to bothered wasting a few CPU cycles. Also my solution will save money for those paying for bandwidth.Jcart wrote:There are several ways to do this, you can set timeouts on your cached versions for instance.. or have a controller decide whether there is new content.
Anyway I'm interested in more on server side caching to cut CPU and database load as well.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
I don't understand, lets say we have a news article database, and we want to check if there have been any new entries. We would simply do a quick COUNT(*) or whatever to check if there are new entries. Evidently, this would take less than fetching all of the articles and displaying them.bokehman wrote:Ok, so really this is just about guessing if the content has changed; no conclusive proof. I'm not saying that is wrong, I'm just trying to clarify the point. So the only way to be certain the page hasn't changed is to test the dynamic parts, is that correct? On the solution above he said to save bandwidth, I understand the server load will be the same though. Often though there is a big mismatch in cpu to connection ratio in favour of the cpu. There certainly is in the case of my server where the connection is the bottleneck so I'm not to bothered wasting a few CPU cycles. Also my solution will save money for those paying for bandwidth.Jcart wrote:There are several ways to do this, you can set timeouts on your cached versions for instance.. or have a controller decide whether there is new content.
Anyway I'm interested in more on server side caching to cut CPU and database load as well.
I can see your logic here but that's not what happens. In the case of an extremely high traffic site there could be any number of caching servers for every webserver and database server and those caching servers have logic that decides the caching without accessing the database. That is the whole point. The caching server has to decide do I handle this request alone or do I hand it over to the real server for a new response to be built.Jcart wrote:quick COUNT(*) or whatever to check if there are new entries.