I am working on an implementation for RSS feeds for a collaboration platform. Say there are several thousands of different collaboration rooms where users can share information, and each needs to publish an RSS feed with news, changes, etc…
Using a plain servlet (i.e. http://www.site.com/RSSServlet/?id=roomID) is costly, every time an RSS client is calling the servlet (and this will happen say every 10 minutes for each user registered to an RSS feed on one of the thousand of rooms) this will trigger the entire servlet lifecycle, which is costly.
On the other hand, keeping a static XML file on the disk for each of the thousands of rooms is costly as well, in terms of hard disk space as well as IO operations…
One more limitation – using already existing frameworks might not be an option…
So, how would you implement RSS feeds in a Java envoronment?
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()ordoPost()methods.I think what you mean to say is that if you have a
doGet/doPostmethod 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/doPostmethod 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
becomes
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.