How about registering this DropDowns in Application Context? This will
ensure Singleton model anyway.

-----Original Message-----
From: Hookom, Jacob John [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, December 03, 2002 8:36 AM
To: Struts Users Mailing List
Subject: RE: [OT] caching drop-down lists


It wouldn't be too difficult to write your own softreference cache that
would store your collections.
 
That way, you can store as much as you want/ that the VM can handle
 
public class DropDownCache()
{
   private Map map;
   
   public Collection getDropDown(String key)
   {
          Collection result = null;
          // or use WeakReference
         SoftReference ref = (SoftReference) this.map.get(key);
         if (ref != null)
         {
               result = (Collection) ref.getObject();
               if (result == null)
               {
                    this.map.remove(key);
               }
         }
        return result;
    }
 
    public void putDropDown(String key, Collection dropDown)
   {
         SoftReference ref = new SoftReference();
         ref.setObject(dropDown);
         this.map.put(key, ref);
   }
}
 
Then, in your BusinessDelegators, simple do a DropDownCache check, if the
object's not there, hit the db and re-grab it, and store it again before
returning it to the Action.
 
-Jacob Hookom

-----Original Message----- 
From: Jarnot Voytek Contr AU HQ/SC [mailto:[EMAIL PROTECTED]] 
Sent: Mon 12/2/2002 6:04 PM 
To: '[EMAIL PROTECTED]' 
Cc: 
Subject: [OT] caching drop-down lists



In our application (and I'm sure most others) we've got a multitude of
drop-down lists used for data entry.  The Collections for the drop-downs are
populated from the database.

This doesn't seem very efficient - to hit the database for a read-only data
every time.

I'd like to cache this data (Business Delegate layer in our case); but I'm
afraid of caching all the drop-down list Collections - I don't want to use
up too much memory.

I'm thinking of implementing some sort of singleton that would cache a
specified number of Collections and remove the least recently used ones as
new ones are requested.

Has anyone implemented this sort of thing?  Am I adding too much complexity
(and overhead)?  Do you think I should just cache them all - after all, I'm
not sure that there will actually be so many as to use an inordinate amount
of memory?

Just thinking out loud...
--Voytek Jarnot

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




-------------------------------------------------------------------
This email is confidential and intended only for the use of the individual
or entity named above and may contain information that is privileged. If you
are not the intended recipient, you are notified that any dissemination,
distribution or copying of this email is strictly prohibited. If you have
received this email in error, please notify us immediately by return email
or telephone and destroy the original message. Thank you. - This mail is
sent via Sony Asia Pacific Mail Gateway. 
-------------------------------------------------------------------

Reply via email to