Chapter 7: Static Meets Dynamic Adding Caches to Reduce Costs

Static content on a website is like a phone book, but imagine how difficult it would be to use your "paper cache" if the numbers inside the phone book constantly changed or if numbers differed based on who was looking them up.  This is why caching dynamic content poses a more difficult problem than caching static content.
Caching Is Powerful

Two things should be clear by now.  First, caching systems vary widely in their implementation, approach, and applicability.  Second, on analysis you can determine which caching approach is right for a specific component to achieve dramatic improvements with respect to both performance and scalability.

In our original article page we witnessed three substantial database operations on every page.  After implementing a variety of dynamic caching solutions we were able to achieve an acceptably high cache-hit rate (nearly 100%) and all but eliminate database queries from our pages.  After users log in for the first time, their left navigation preferences are stored in their cookie, and it is unlikely that they will ever lose their cookie and require a database query to reset it.  Articles data, which once required two queries to retrieve, are now compiled into a valid web page to be served directly by Apache, alleviating both database access and the dependency on an external caching mechanism.

Although the examples in this chapter are implemented in perl using the Apache::ASP embedding system, all the caching techniques presented can be implemented using almost any interpreted scripting language.  The goal was to present concepts.  Aside from the two-tier execution approach, all the concepts presented can be implemented in any language and in any architecture–even outside the Web.

The key to successful caching is understanding the true nature of your data: how frequently it is changed and where it is used.



Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Cookie storage

Slac's picture

Thanks for this good summary.

I have got some problems with cookie caching, because only small informations can be stored in cookies and this form of caching could come together bandwith problems on the client side.

So I think it can be better a combination of cookies and server caching. For example: A user comes and first time I read the cookie, and the next page query I can use serverside cache (created from cookie's datas). I change the cookie only when the user change his preferences.

In this example the process seems so:

1. I check the serverside cache, if found, then ok, else
2. I check the cookie, if found and valid, then ok, else
3. I get the informations from the database and write in cache and in cookie

And 30 minutes after the last page query (same as by sessions) the serverside cache can be invalidated by a timer.

Same problem

Ray's picture

My programmer Adam had the same problem. He figured out a compact way to server over 53 million of our blog articles on one little server.

The speed is awesome and googlebot is busy busy.. my blogs


Good Summary

Schifoan's picture

Some of the technics are often used, but this article is a good summary for caching dynamic pages and content.

What an article! Sure beats

Student Organization Leader's picture

What an article! Sure beats the caching concepts discussed in my University's computer architecture class. Can't say that I manage web sites with enough traffic to need such levels of performance refining, but it sure is fun to learn.

White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState