CHAPTER 14 – PHP Design Tip #2: Cache!
Caching is a great way to reduce the response time of your site. By having caching in mind during the design phase, you can layer your application so that adding caching is straightforward. When you design for caching, consider issues like expi- ration schemes from the beginning rather than hacking it in as an afterthought. Figure 14.3 shows a high-level diagram of an application separated into a Database Server, an Application Logic layer, and a Display Logic layer.
Browser Display Logic Templates Application Logic Database Server Fig. 14.3 A cleanly layered web application. Here, the Database Server includes the database itself (such as MySQL or Oracle). The Application Logic layer hides SQL and database details behind a PHP-based API. Finally, the Display Logic layer interfaces the user, man- ages forms and templates, and communicates with the database through the Application Logic layer. You may add caching between every layer of your application, as shown in Figure 14.4. Browser Output Cache Display Logic Compiled Templates Call Cache Source Templates Application Logic Query Cache Database Server Fig. 14.4 A cleanly layered application with a cache between each layer. This design captures four distinct types of cache functionality: Database query/result caching Call/return value caching Template caching/code generation Output caching