struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hookom, Jacob John" <hooko...@uwec.edu>
Subject RE: [OT] caching drop-down lists
Date Tue, 03 Dec 2002 00:36:23 GMT
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:Voytek.Jarnot@MAXWELL.AF.MIL] 
	Sent: Mon 12/2/2002 6:04 PM 
	To: 'struts-user@jakarta.apache.org' 
	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:struts-user-unsubscribe@jakarta.apache.org>
	For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>
	
	


Mime
View raw message