I am working on a web service servlet running on Google App Engine using Spring 3.1, and since I'm pretty new to this game, I simply don't know how I should be caching things. It seems like there are a number of places I can put things to be maintained during the lifetime of my servlet:
- Application context. Defining beans here would allow me to easily inject them into my code. This seems like the easiest solution, just scope my beans to be singletons.
- Servlet context. For this, when my servlet starts up, I can put things in the ServletContext by grabbing the instance of it, and doing a
setAttribute(). - Memcache. I haven't looked into this much yet, but I imagine I would just get an instance of the cache, and shove an object into it like the ServletContext.
The specific case I'm curious about is for creating user accounts. I want to keep a HashSet of all user IDs so that I can check if the requested user ID is already in use.
Beyond the specific case above, including cases for using each of the different technologies would be appreciated.