Let’s see how Restbucks can take advantage of caching to improve
the distribution of its menu. The Restbucks menu is an XML document that
is consumed by third-party applications such as coffee shop price
comparators and customers. The menu resource is dynamically created from
the Restbucks product database. Every time the menu service receives a
GET request for the menu, it must
perform some logic and database access.
Restbucks would like to ensure that its menu service isn’t overwhelmed by thousands of requests from external services. But instead of deploying more servers or paying for more bandwidth, Restbucks decides to make use of the Web’s caching infrastructure.
This caching infrastructure includes reverse proxies and proxy caches, as well as local caches. Some consumers of Restbucks’ menu service may opt to use their local caches to speed up their systems, knowing that consistency with Restbucks’ data isn’t always guaranteed. Doing so is easy: Example 6-8 shows some simple .NET HTTP client code that uses the WinINet cache provided by Microsoft Windows Internet Services. The WinINet cache is the same local cache that Internet Explorer uses, and so has a large installed base.
To take advantage of local caching, we need only add a
RequestCachePolicy instance to our request.
The policy is initialized with a
RequestCacheLevel.Default enum value, which
ensures that the local cache is used to try to satisfy the request. If
the local cache can’t satisfy ...