tailieunhanh - Developing Large Web Applications- P26

Developing Large Web Applications- P26:This book presents a number of techniques for applying established practices of good software engineering to web development—that is, development primarily using the disparate technologies of HTML, CSS, JavaScript, and server-side scripting languages. Whereas there are many books on how to use languages, how to use libraries, and how to approach software engineering, this is the first book to codify many of the techniques it presents. These techniques will make the components of your own web applications more reusable, maintainable, and reliable | Caching for Pages Just as you can cache the contents of individual modules that you don t expect to change frequently you also can cache the contents of entire pages. The process for implementing this is similar to that for modules. You create a CacheablePage class and override the default implementations for the create and get_page methods. The start of create is a logical place to insert the code for generating the hash and searching the cache. At this point you can inspect parameters for generating the page even before taking the time to load data for the page. If the page can use the cache fetch the completely assembled page instead of generating it from scratch in get_page. If the page cannot use the cache generate the page in the traditional manner during which some caching may still be utilized by modules remember and cache the completely assembled page at the end of get_page for the next time. A further opportunity for caching of course occurs when the data for the page is loaded. This type of caching is performed best by the backend since it has the visibility into how the data is stored and ideally these details should be abstracted from the user interface. Therefore we re not going to look at an example of this in this book although it clearly plays an important part of most large web applications. Whenever you expect to do a lot of caching keep in mind that caching can cause its own performance issues as memory becomes too full. In this case a system may begin to thrash as it begins to spend more time swapping virtual pages in and out of memory than doing other work. You can keep an eye on this by running top on Unix systems and monitoring the process in charge of swapping for your system. Caching with Ajax Ajax provides another opportunity for caching. In Chapter 8 we discussed the usefulness of the MVC design pattern in managing the separation between data presentation and control in an Ajax application. Here we revisit Example 8-15 with caching in .