Cache Data Used in Pages
In an enterprise application, how and
where data is cached is usually controlled by a servlet. Because JSP
uses servlet technology as its foundation, a JSP page has access to
the same standard cache repositories as a servlet: sessions for
per-user caching and context attributes for application-wide caching.
Hence, a JSP page can easily read the cached data maintained by
servlets with the standard
<jsp:getProperty>
action and JSTL EL expressions.
While letting a servlet handle caching is typically the right choice, there are exceptions to this rule. Read-only data that is only of marginal importance to the application is often better managed by the JSP page that renders it. One example of this is an external news feed, used just to make the web application more appealing to its users. A JSP page can retrieve the news in XML from a Rich Site Summary (RSS) service, parse it, and transform it to a suitable format using the JSTL XML actions. With a templating solution such as the one described earlier, the news listing can easily be included in all pages throughout the site without interfering with the main application code.
Caching is, of course, important for this scenario; retrieving and formatting the data is time- and processor-intensive. Incurring this cost for every request is a waste of resources and loads the RSS server unnecessarily. The processed data can be cached using standard and JSTL actions, like this:
<c:set var="cachePeriod" value="${60 *60 ...