Click here to Skip to main content
15,907,687 members
Articles / Programming Languages / PHP
Alternative
Tip/Trick

Caching Output in PHP

Rate me:
Please Sign up or sign in to vote.
4.43/5 (3 votes)
30 Mar 2010CPOL 6.9K   1   1
You should not define the object identifyer at the top of each page (because then you have to write out the same bit of code each time u want to access a object within a class.- (Insted Use a included class)Cachecache_class.phpExample Classclass Cache {function...
You should not define the object identifyer at the top of each page (because then you have to write out the same bit of code each time u want to access a object within a class.

- (Insted Use a included class)

Cache
cache_class.php
Example Class
class Cache {
function cache_start(){
// Start Cache CODE
}

function cache_end(){
// End Cache Code
}

}


At the bottom of the class we will need to add the object identifyer, this is a much better way of using objects within our class because rather then defining object identifyers all the time we can just define one identifyer.

Once we include the file which contains our php cache class we can then use the functions which we have just created to enable cache.


$cache = new Cache();


Using Objects Within The Class
include('includes/cache.php');

$cache->start();

$chache->end();

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Generali used a cache class but i found that i rather not use the o... Pin
simplu13-Jun-10 4:11
simplu13-Jun-10 4:11 
i used a cache class but i found that i rather not use the one with __destruct because i did not want to cache the errors too. My application was mvc so the request_uri was always index.php and the _get variable was the page i was showing, but if i had a page in the _get var that did not exist like "help" and page help did not exist, it would return the 404 error but it would cache the error page as help.. so i used the $cache->start(); & $cache->end(); and for the end i used a parameter like $cache->end($error) and $error was true or false depending if i would return an error or not. In that case i would know if i have to cache the file not Smile | :) .
So from my point of view the Alternate cache with start and end would be rather usefull than the other one Smile | :)

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.