HomePHP Caching Result Sets in PHP: Porting the Code to PHP 5
Caching Result Sets in PHP: Porting the Code to PHP 5
In this part of the series, you will see in detail an updated version of each class that composes the caching system, for a correct implementation in PHP 5. Also, the “Cache” class will be modified to work with an array processor class that handles array operations. It should help refresh your memory of techniques related to object-oriented programming.
Welcome to the fifth part of the series “Caching result sets in PHP.” If you’ve been a patient reader, and followed the previous articles in this series, then you probably have a decent grounding in the different methods of developing a result set caching system, without the need to scratch your head looking for more complex solutions.
As a matter of fact, storing a complete result set in a cache file for faster data retrieval and reduced server overload is an extremely versatile technique that brings to developers a greater level of flexibility, since it allows single or multiple post processing of the data, while keeping the inherent benefits of having a caching mechanism working transparently in the backend of a website.
Many websites that use a database as a direct way to store contents that don’t change very often (naturally static), such as a product catalog, or a list of articles, to name a few cases, can significantly improve their performance by implementing a caching solution.
Although the concept behind data caching certainly is not new, as modern developing techniques have emerged and found their place in the market, several approaches may be successfully taken.
Particularly, when working with PHP, where either a procedural programming or an object-oriented approach is taken for solving many development issues, the subject is even richer with possibilities. Keeping in mind this concept, after going through the previous articles, we’ve developed a couple of procedural scripts that might be useful for implementing in small applications.
However, we’ve not forgotten all the benefits of developing some classes that can be integrated within an expandable caching system. Indeed, if we step back for a while to the previous article, we’ve built a time expiry triggered caching class, which allows fast implementation in web applications.
As I mentioned previously, the whole set of developed classes that worked in PHP 4, need to be updated to PHP 5, in order to take advantage of the powerful Object Model that was implemented in this version. So, let’s not waste more time in preliminaries and jump straight into the code. You’ll have a good time reading, I promise.