Приглашаем посетить
Хомяков (homyakov.lit-info.ru)

Caching Issues

Previous
Table of Contents
Next

Caching Issues

Any caching system you implement must exhibit certain features in order to operate correctly:

  • Cache size maintenance As my refrigerator phone list grows, it threatens to outgrow the sheet of paper I wrote it on. Although I can add more sheets of paper, my fridge is only so big, and the more sheets I need to scan to find the number I am looking for, the slower cache access becomes in general. This means that as I add new numbers to my list, I must also cull out others that are not as important. There are a number of possible algorithms for this.

  • Cache concurrency My wife and I should be able to access the refrigerator phone list at the same timenot only for reading but for writing as well. For example, if I am reading a number while my wife is updating it, what I get will likely be a jumble of the new number and the original. Although concurrent write access may be a stretch for a phone list, anyone who has worked as part of a group on a single set of files knows that it is easy to get merge conflicts and overwrite other people's data. It's important to protect against corruption.

  • Cache invalidation As new phone books come out, my list should stay up-to-date. Most importantly, I need to ensure that the numbers on my list are never incorrect. Out-of-date data in the cache is referred to as stale, and invalidating data is called poisoning the cache.

  • Cache coherency In addition to my list in the kitchen, I have a phone list in my office. Although my kitchen list and my office list may have different contents, they should not have any contradictory contents; that is, if someone's number appears on both lists, it should be the same on both.

There are some additional features that are present in some caches:

  • Hierarchical caching Hierarchical caching means having multiple layers of caching. In the phone list example, a phone with speed-dial would add an additional layer of caching. Using speed-dial is even faster than going to the list, but it holds fewer numbers than the list.

  • Cache pre-fetching If I know that I will be accessing certain numbers frequently (for example, my parents' home number or the number of the pizza place down on the corner), I might add these to my list proactively.

Dynamic Web pages are hard to effectively cache in their entiretyat least on the client side. Much of Chapter 9, "External Performance Tunings," looks at how to control client-side and network-level caches. To solve this problem, you don't try to render the entire page cacheable, but instead you cache as much of the dynamic data as possible within your own application.

There are three degrees to which you can cache objects in this context:

  • Caching entire rendered pages or page components, as in these examples:

    • Temporarily storing the output of a generated page whose contents seldom change

    • Caching a database-driven navigation bar

  • Caching data between user requests, as in these examples:

    • Arbitrary session data (such as shopping carts)

    • User profile information

  • Caching computed data, as in these examples:

    • A database query cache

    • Caching RPC data requests


Previous
Table of Contents
Next