Rob,

I have written a PersistenceManager class that handles all database
access and uses the SQLData interface to map java objects to
User Defined Types in the oracle database. Every request now
has to create a new instance of the persistencemanager so there is
no sharing whatsoever. I would like the persistencemanager to look
in the object cache first and if the object is not there retrieve it
from the database. I need a way to keep this cache in memory
so all requests can use the same cache.

I would do two things:


1) Put your PersistenceManager in the application scope, and re-use it all the time instead of doing "new PersistenceManager" for every request.

2) Have your PersistenceManager do its own cachine. One of my favorite object caching techniques is to simply use a java.util.WeakHashMap. The WeakHashMap works with WeakReferences, so you can fill it with data, and the GC will purge some of it for you if it needs some memory back.

It works just like any other Map, except that you aren't guarenteed to get your object back, later :)

This may sound sketchy, but it's a pretty good cache because it works the same all the time: if you have a cache miss, you go to the database.

Don't forget that caches are complicated: when data changes, you have to make sure that the cache gets updated. If you have multiple clients and a single database, this gets to be a real nightmare. Only cache things that don't need to be sync'd up-to-the-minute. For those things, *always* go back to the db.

-chris


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to