How to cache things for my servlet?

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:

  1. 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.
  2. 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().
  3. 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.

Answers


In your specific case I recommend you to use a persistent storage, like the datastore or cloud sql (you can see all alternatives here).

Memcache is not an option, since you can't control how many elements are stored. And any application context is not a solution either, since the instances are in practice being loaded and reloaded many times in different datacenters.

Note also that AppEngine provides support for using Google Accounts or OpenId via the Users Service.


Need Your Help

Identifying if value is in Excel File (with Pandas)

python pandas xls

I have a blacklist with numbers which are read from an .xls file (can't change that fact). While iterating over a large number of things, I have to check if the current number of my things is in said

Extracting rightmost N bits of an integer

java algorithm bit-manipulation

In the yester Code Jam Qualification round http://code.google.com/codejam/contest/dashboard?c=433101#s=a&a=0 , there was a problem called Snapper Chain. From the contest analysis I came to know...