HomePHP Developing a Caching Class for an MVC-based Framework in PHP 5
Developing a Caching Class for an MVC-based Framework in PHP 5
In this seventh part of the series, I add a cache class to the classes that comprise the MVC-based framework we're building. The new class uses the file system as the underlying backend for caching data, but it’s also possible to create one that caches data on shared memory, a SQLite database and so forth. Indeed, numerous possibilities exist.
Without a doubt, the Model-View-Controller design pattern is one of the most useful approaches these days for developing web applications that keep their business and application logic isolated (at least partially) from visual presentation.
As a PHP developer, you may already have mastered the key concepts that surround the application of this popular structural pattern by implementing it successfully within your own web-based programs. If that’s the case, then feel free to congratulate yourself and keep up the good work.
However, it’s also fair to say that there are many PHP programmers who are taking their first steps into the vast terrain of object-oriented web development and want to learn, among other things, how to apply the MVC paradigm in a real-world project.
If you belong to this second group, then I suggest you start reading this series of articles. It will teach you in a step-by-step fashion how to build a fully-functional, object-based framework that will stick to the schema dictated by the Model-View-Controller design pattern.
Of course, if you’ve already read all of the articles that precede this one, then at this point you’re familiar with the foundation for building a basic MVC-driven framework like the one mentioned above. In those tutorials I began developing a set of loosely-coupled classes for tackling some common tasks, such as routing HTTP requests to the appropriate controllers and interacting with MySQL, as well as sanitizing user input and automatically generating web forms.
I know that it’s still hard to see how these classes can be put to work together under the umbrella of the MVC pattern, but for the moment bear with me and be patient, since it’s time to add another class to the existing stack.
Yes, as this article’s title clearly suggests, in the following lines I’m going to incorporate into the framework a basic cache class. This will give it the ability to cache both database result sets and HTML output.
Want to learn the full details for how this class will be created? Start reading now!