You say that a new http request to your servlet "will trigger the entire servlet lifecycle", which as Alexander has already pointed out, isn't exactly true. It will simply trigger another method call to your doGet()
or doPost()
methods.
I think what you mean to say is that if you have a doGet
/doPost
method which contains code to build the data needed for the RSS feed from scratch, then each request triggers this fetching of data over and over again.
If this is your concern, and you are ruling static content out, simply modify your Servlet doGet
/doPost
method to cache the RSS content that you would otherwise return, so that handling each request does not mean re-fetching all of the data all over again.
For example
public void doGet(HttpServletRequest request, HttpServletResponse response) {
//build the objects you need for the RSS response
Room room = getRoom(request.getParameter("roomid"));
//loadData();
//moreMethodCalls();
out.println( createRssContent(...) );
}
becomes
Map rssCache;
public void doGet(HttpServletRequest request, HttpServletResponse response) {
//Map is initialized in the init() method or somewhere else
String roomId = request.getParameter("roomid");
String rssDocument = rssCache.get(roomId);
if (rssDocument == null) {
//build the objects you need for the RSS response
Room room = getRoom(roomId);
//loadData();
//moreMethodCalls();
rssDocument = createRssContent(...);
rssCache.put(roomId, rssDocument);
}
out.println( rssDocument );
}
If you only want to store items in a "cache" for a certain amount of time you can use one of a dozen different caching frameworks, but the idea here is that you don't reconstruct the entire object graph necessary for your RSS response with each http request. If I am reading your original question right then I think that this is what you hoping to accomplish.