Cache Pages

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

How would I do dynamic/processing caching, cause I have a page that is included on every page of my website that does 3 querys to my database and I don't want to do them if it doesn't need to because most of the time the data won't change, unless the user's points goes up.
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

cache folder of files?

specify the length that the cache is valid for, then if the filemtime() is within that limit, include the cached file, instead of the php file with the queries.
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post by bokehman »

tecktalkcm0391 wrote:I have a page that is included on every page of my website that does 3 querys to my database
MySQL does its own caching. All results are cached so that repeat queries are near instaneneous. The cache is store until the table is updated somehow (through INSERT, UPDATE or DELETE).
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

OK, good, I didn't know that.
bdlang
Forum Contributor
Posts: 395
Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US

Post by bdlang »

I'm not clear on the cache process (I've not been one to utilize caching in my applications to this point, since most of them are backends for company databases). Is the assertion that dynamic content scripts, i.e. one that pulls data down from a (or many) SELECT statements should not bother with a generalized cache mechanism because MySQL caches the SELECT output? That the cache should be for static content only?
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

I just found this, and can't I just use:

Code: Select all

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");    // Data passata
   header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
                                                        // sempre modificato
   header("Cache-Control: store, cache");  // HTTP/1.1
   header("Cache-Control: post-check=1 pre-check=1", true);
   header("Pragma:cache");                          // HTTP/1.0
To make it cache the page that is sent to a user. (Browser Caching)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

bdlang wrote:I'm not clear on the cache process (I've not been one to utilize caching in my applications to this point, since most of them are backends for company databases). Is the assertion that dynamic content scripts, i.e. one that pulls data down from a (or many) SELECT statements should not bother with a generalized cache mechanism because MySQL caches the SELECT output? That the cache should be for static content only?
Let me give you an example, I had a spider that would run once a day to check for new content throughout several major site networks, this collected a massive amount of information and page loads were getting to a couple seconds (which sucks). Instead of pulling up a massive list of datum dynamically, I would cache the data once per day (each time the spider ran).

There are many ways to deal with the logic behind caching, be it a timeframe or logical.. but caching is not limited to static content at all. By eliminating the need to re-run processes that consume processor cycles, caching become very important when there is a need for high performance.
Post Reply