This document explains the design of the caching support..
In many cases, application-level caching can be used to obtain a more performant application. An example of this is a typical web application, which needs to generate a page containing links to several items. In this case, to generate the page itself, it needs to first needs to obtain a list of items to put on the page. The returned HTML for the page refers to these items. As a result, the browser sends a separate request for each item on references on the page. In this case, caching can be used to obtain an increase in performance since the results of the initial query can be cached.
The design provides a Cache interface which represents a certain cache. The cache provides options for setting and retrieving an object based on a key and for removing objects from the cache. In addition there is a utility CachedObject that provides a method to obtain an object from the cache by key and, if not found, execute a callback to compute the object.
The Cache interface encapsulates a certain cache.
The following cache implemenations are provided:
This scenario describes usage of CachedObject.
At construction of the CachedObject, the user must pass a Computation callback to the object which is used to compute an object. To obtain the object, get() is called. This first looks in the cache if the object is there, and if not, executes the computation callback to compute the object.