simple caching
I have an application which recieves request from a client to send back an xml via a servlet. The information is retrieved from the database and then XMLBeans are used to marshall this info into an xml file.
Currently there are about 15 different xmls which are formed as a result of this process. Now as database connection is an expensive operation and one would not like to go through to the database each time to grab the information, the plan is to somehow cache these xml and setup a time to live property for this cache after which the cache is going to refresh each time.
I am thinking of creating a HashMap of these xml within the init method of the servlet. Where there would be a timer thread setup to refresh the data every x amount of time. Once this HashMap is populated over there I don't have to grab info from the DB each time and since it is readily available I can just get it from the cache itself.
What do you think about this and do you feel there could be a better way of doing this.

