More periodic refresh with JSTL c:import
This is a followup to a recent post to this group. The snippet below imports a page and stores it into variable x if variable x is more than 5 five minutes old. This makes the page load fast for the great majority of hits. However, if traffic to the site is slow, let's say a steady one hit every 6 minutes, then each surfer experiences a very slow response time as the site goes through the slow c:import routine to load x before showing the page. Meanwhile, my webserver is sitting idle for the remaining time between hits. Is there a tag or other technique one can use to instruct the webserver to keeps variable x up-to-date (ie, not more than 5 minutes old) in the background without waiting for a hit before noticing the variable is stale? Brian - c:set var=cachePeriod value=${5 * 60 * 1000} / jsp:useBean id=n class=java.util.Date / c:if test=${(n.time - cacheTime) cachePeriod} c:remove var=x scope=application / /c:if c:if test=${empty applicationScope.x} c:set var=x scope=application c:import url=channel.jsp c:param name=rssUrl value=http://www.slowurl.rss; / /c:import /c:set jsp:useBean id=now class=java.util.Date / c:set var=cacheTime value=${now.time} scope=application / /c:if c:out value=${applicationScope.x} escapeXml=false / -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
periodic refresh with JSTL c:import
This snippet prints out up-to-date information but it is slow ... c:import url=channel.jsp c:param name=rssUrl value=http://www.slowurl.rss; / /c:import This snippet makes it fast but stale... c:import url=channel.jsp var=x scope=application c:param name=rssUrl value=http://www.slowurl.rss; / /c:import c:out value=${applicationScope.x} escapeXml=false / How can one use JSTL to do something in between, such as to update the c:import once an hour? c:if test=??? test if applicationScope.x is more than an hour old ??? c:import url=channel.jsp var=x scope=application c:param name=rssUrl value=http://www.slowurl.rss; / /c:import /c:if c:out value=${applicationScope.x} escapeXml=false / Brian -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: periodic refresh with JSTL c:import
On Wed, 18 Dec 2002, Brian Buckley wrote: How can one use JSTL to do something in between, such as to update the c:import once an hour? c:if test=??? test if applicationScope.x is more than an hour old ??? c:import url=channel.jsp var=x scope=application c:param name=rssUrl value=http://www.slowurl.rss; / /c:import /c:if c:out value=${applicationScope.x} escapeXml=false / You could create a Date object and compare the time property of this object against the current time; Hans has shown how to do this in previous messages. It might be easier to use the Cache Taglib, which isn't part of JSTL but does exactly what you're looking for. -- Shawn Bayern JSTL in Action http://www.manning.com/bayern -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
periodic refresh with JSTL c:import
Correction -- I meant to include an c:if clause around the fast but stale way. c:if test=${empty applicationScope.x} c:import url=channel.jsp var=x scope=application c:param name=rssUrl value=http://www.slowurl.rss; / /c:import /c:if c:out value=${applicationScope.x} escapeXml=false / Thanks. -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: periodic refresh with JSTL c:import
You could create a Date object and compare the time property of this object against the current time; Hans has shown how to do this in previous messages. It might be easier to use the Cache Taglib, which isn't part of JSTL but does exactly what you're looking for. Thanks, Shawn. I found the Hans example and it does just what I need. In case you failed to notice :), my snippets were lifted from JSTL In Action. Excellent book. -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]