Okay, so I've got page compression turned on, and I'm using APC page accelerator. But I've got a client site I'm working on that does a lot of busy work on the homepage but unfortunately only gets updated about once a day. Is there a quick and easy trick that I can use in my .htaccess (Apache2) or PHP5 page such that I tell the browser to cache the homepage at least all day unless the user forces a reload?
Sorry to sound so dumb on this, but I have never needed to do this before. This is the first client I've had where I'm doing so much on the homepage per his requirements, and I feel if it's slow now, it'll be REALLY slow when it gets hit by several users.
Page Caching
Moderator: General Moderators
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: Page Caching
Trivial caching is ummm...well trivial. Haha.
Although it sounds like you want to cache on the client side too -- unless the client deliberately refreshes.
Basically the idea is this...
0. Check cache URI -- use cache and skip steps 1 & 2
1. Build page HTML
2. Save page HTML
It's really that simple for trivial full page caching. Have a cron job delete the cache files every 24 hours.
Things get tricky when you need partial caching and event based flushing...
Although it sounds like you want to cache on the client side too -- unless the client deliberately refreshes.
Basically the idea is this...
0. Check cache URI -- use cache and skip steps 1 & 2
1. Build page HTML
2. Save page HTML
It's really that simple for trivial full page caching. Have a cron job delete the cache files every 24 hours.
Things get tricky when you need partial caching and event based flushing...
-
supermike
- Forum Contributor
- Posts: 193
- Joined: Tue Feb 28, 2006 8:30 pm
- Location: Somewhere in the Desert, USA
Re: Page Caching
Hockey, you may not have seen this article. I just read it after posting my original statement. It's a bit difficult for me to comprehend just yet -- I mean, it's hard to think when I'm under such terrible project deadlines right now.
http://www.askapache.com/htaccess/speed ... ching.html
http://www.askapache.com/htaccess/speed ... ching.html
Re: Page Caching
Code: Select all
$uri_hash=md5($_SERVER['REQUEST_URI']);
if(file_exists('cache/$uri_hash'))
{
print file_get_contents('cache/$uri_hash');
}
else
{
ob_start();
//do your stuff here
$page=ob_get_contents();
ob_end_clean();
file_put_contents('cache/$uri_hash',$page);
}
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: Page Caching
supermike: I think that .htaccess hack is probably implementing client side caching. That it, it's telling the browser which files to cache on the client side and for how long.
The method I show is server side caching. I prefer server side because then you have explicit control not to mention programatic control over your cache.
Either will work. I imagine all you have to do with .htaccess approach is change the expiry date to sometime the past to flush the client cache and re-download the HTML files.
The method I show is server side caching. I prefer server side because then you have explicit control not to mention programatic control over your cache.
Either will work. I imagine all you have to do with .htaccess approach is change the expiry date to sometime the past to flush the client cache and re-download the HTML files.