Howdy,
If you're using servlets,
getServletContext().setAttribute("myPersistenceManager",
myPersistenceManager) would do the trick. If you're using JSPs, it's
pageContext.setAttribute(...).
The WeakHashMap is one approach: not one I'd use initially, but only if
you run into issues with a more conservative approach.
Yoav Shapira
Millennium ChemInformatics
>-----Original Message-----
>From: Rob Augustinus [mailto:[EMAIL PROTECTED]
>Sent: Monday, November 24, 2003 2:38 AM
>To: Tomcat Users List
>Subject: Re: shared object cache
>
>
>thanks,
>
>1) That's exactly what I would like to do, but I'm not quite sure how
to do
>this. Could you point me to some documentation?
>
>2) I have thought about the complications of the cache, and indeed I
need
>to
>be carefull. On the other hand though it is not that critical in this
>application.
>
>
>
>Christopher Schultz wrote:
>
>> 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]
>>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
This e-mail, including any attachments, is a confidential business communication, and
may contain information that is confidential, proprietary and/or privileged. This
e-mail is intended only for the individual(s) to whom it is addressed, and may not be
saved, copied, printed, disclosed or used by anyone else. If you are not the(an)
intended recipient, please immediately delete this e-mail from your computer system
and notify the sender. Thank you.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]