struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kris Schneider <k...@dotech.com>
Subject RE: [OT] caching strategy
Date Mon, 23 Jun 2003 13:39:19 GMT
And as the Javadoc for SoftReference hints at, you can even combine strategies
by maintaining strong references to the most recently used items to "lock" them
in the cache and letting GC take care of when to dispose of the least recently
used items.

Quoting "Hookom, Jacob" <Jacob.Hookom@redline.mckhboc.com>:

> LRU - Least Recently Used.  You define your cache size and every time an
> object is created or "grabbed" from the cache, it gets promoted to the top
> of the cache, or you can have its timestamp reset to 'now'.  As objects are
> created, you check to see if the cache is too big, if so, take the oldest
> or
> the item from the bottom of the stack out of the cache.
> 
> Softly Referenced - Instead of putting the actual object as the value in a
> Hashmap, wrap it in a 'SoftReference' which may loose the object depending
> on how the garbage collector handles things with memory resources.  This
> allows you to have as much as you want for cached objects, but keep in
> mind,
> if the VM needs more memory, your softly-referenced objects are on the
> chopping block.  Depending on the VM to manage your cache can be a little
> bit more expensive for processing and you will see the GC running a little
> bit more frequently-- the trade off is that you've maximized your memory
> usage and with some VM arguments, you can reduce the GC runs into a
> manageable amount on an enterprise system.
> 
> public Object fetchObject(Object identity)
> {
> 	Object result = null;
> 	SoftReference ref = this.map.get(identity);
> 	if (ref != null)
> 	{
> 		result = ref.get();
> 		if (result == null)
> 		{
> 			ref = null;
> 			this.map.remove(identity);
> 		}
> 	}
> 	return result;
> }
> 
> --------
> Jacob Hookom
> Senior Programmer/Analyst
> McKesson Medical Surgical
> Golden Valley, MN
> 
> -----Original Message-----
> From: Erik Price [mailto:eprice@ptc.com]
> Sent: Friday, June 20, 2003 3:49 PM
> To: Struts Users Mailing List
> Subject: Re: [OT] caching strategy
> 
> 
> 
> 
> Hookom, Jacob wrote:
> > create primary keys for your data, create an identity object to represent
> > legacy data, create a hashmap or cache interface and use either LRU's or
> > Softly referenced caching.  Pretty straight forward.  Logic would be
> "select
> > primary keys + lastModified" if changed or not found, create, else pull
> from
> > cache.
> 
> Okay I understand the first part -- proxy the legacy data entities with 
> Java objects, and use a HashMap-based cache (perhaps using the primary 
> keys as the hash's keys).  But...
> 
> What are LRU's?  Softly referenced caching -- have a particularly good 
> resource on this topic?
> 
> 
> Erik

-- 
Kris Schneider <mailto:kris@dotech.com>
D.O.Tech       <http://www.dotech.com/>

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Mime
View raw message