PHP Basic Caching

Caching and optimisation go hand in hand, when it comes to lowering the resource hits on your server and speeding up delivery of pages there are a few crucial areas we should look at. One being delivering compressed script to a browser that can handle it. the other being caching.

caching is essentially storing a composite of an event or events in either a database, file on the clients system or file on the server.

Database caching is in use on many Content Managed websites such as drupal.org. The type of caching being used here is where the result of a set of common events, in this case individual queries, are grouped together and stored. the benefit being that the application can check the cache table before having to run multiple queries again.

The other methods of caching involve creating static HTML files either locally or centrally on the server. These files often will often have an expiry tag included to tell the script when it should regenerate them. The huge advantage of this method is that it removes completely or substantially reduces the need to query the database.

Below we have a very basic caching system, which could be expanded by using Php Output Buffering. It is an expansion of our PDO Method found here.

Author: 
John Rose
AttachmentSize
Basic Caching Script (base-caching.tar)11.5 KB
Valid XHTML 1.0 Strict