One basic way to do caching is use the output buffering.
Put
ob_start();
at the start of your script, before you write any HTML. At the end, after you've written all the HTML, put
ob_end_flush();
That sends the contents of the buffer to the client with headers. To cache the page instead of sending it, you can make use of ob_get_contents(); and save the result as a file. Then the next time that page is requested, serve that file instead of rebuilding the page. After the file is a certain age, delete it and rebuild the page.
That's a basic way of doing caching. The problems arise when you want to dynamically add a value in the HTML which is different for each visitor, say if you're dynamically writing JS. Then it gets a bit more tricky....
|