I'm not sure why all this complexity is necessary. Can't you use something more efficient, like a simple _ delimited string for the key? The cache has built in hierarchical removal for keys in this form . . .
How the items are retrieved is not exposed to the user of JCS. There is no interface that specifies how to make a complex key. Maybe there should be an interface or the keys should be restricted to strings. . . This is something to consider. Something along the lines of what you are doing should work, but I suggest that you use a string key if possible. It is more efficient and predictable. Aaron > -----Original Message----- > From: Matthew Cooke [mailto:[EMAIL PROTECTED] > Sent: Tuesday, February 24, 2004 10:07 AM > To: Turbine JCS Users List > Subject: Re: Cache returning unexpected items. > > Paulo, > > Ok :) sorry - I *nearly* included all the useful methods, but we also have > this > method on RealCacheKey > > public int hashCode() { > return myMultipartKey.hashCode(); > } > > Sorry I didn't include this before. > > Matt, > > > paulo caroli wrote: > > Hey Matt, > > > > Check this link: > > http://www.cafeaulait.org/course/week4/38.html > > > > "Anytime you override equals() you should also override hashCode(). The > > hashCode() method should ideally return the same int for any two objects > > that compare equal and a different int for any two objects that don't > > compare equal, where equality is defined by the equals() method. This is > > used as an index by the java.util.Hashtable class. " > > > > Paulo > > > > > > > > > > -----Original Message----- > > From: paulo caroli [mailto:[EMAIL PROTECTED] > > Sent: Tuesday, February 24, 2004 10:46 AM > > To: 'Turbine JCS Users List' > > Subject: RE: Cache returning unexpected items. > > > > Matt, > > > > I advice you to test your key comparison to ensure it is working. > > For some cases you need to implement the public int hashCode() method as > > well as the public boolean equals(Object obj) method. > > Thanks, > > > > Paulo > > > > > > -----Original Message----- > > From: Matthew Cooke [mailto:[EMAIL PROTECTED] > > Sent: Tuesday, February 24, 2004 6:01 AM > > To: Turbine JCS Users List > > Subject: Re: Cache returning unexpected items. > > > > > >>How are you comparing the keys? > >>Thanks, > >> > >>Paulo > > > > > > Paulo, > > > > Maybe that is the problem. Does the key object need to be comparable or > > something? > > (appologies for long post - I've tried to include most of the relevant > key > > related code) > > > > Here are the important parts of the key object we use: > > > > public class RealCacheKey implements CacheKey { > > private Collection myMultipartKey = new HashSet(); > > > > public RealCacheKey(HttpServletRequest aServletRequest) { > > addURIParametersInto(myMultipartKey, aServletRequest); > > } > > > > <...snip...> > > > > public static void addURIParametersInto(Collection aCollection, > > HttpServletRequest aRequest) { > > Enumeration names = aRequest.getParameterNames(); > > > > while (names.hasMoreElements()) { > > String aKey = (String) names.nextElement(); > > if (!isCacheBuster(aKey)) { > > String[] values = aRequest.getParameterValues(aKey); > > aCollection.add(new MapEntry(aKey, > Arrays.asList(values))); > > } > > } > > } > > > > private boolean equals(RealCacheKey another) { > > return myMultipartKey.equals(another.myMultipartKey); > > } > > > > public boolean equals(Object another) { > > return (another instanceof CacheKey) && equals((RealCacheKey) > > another); > > } > > <...snip...> > > } > > > > The cachekey interface extends serializable. > > The map entries are serializable and look like this: > > > > public class MapEntry implements java.util.Map.Entry, Comparable, > > Serializable { > > private static final String NULL = "null"; > > private Object key; > > private Object value; > > > > public MapEntry(Object aKey, Object aValue) { > > super(); > > this.key = (aKey == null) ? NULL : aKey; > > this.value = (aValue == null) ? NULL : aValue; > > } > > > > <...snip...> > > > > > > Cheers, > > Matt. > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: turbine-jcs-user- > [EMAIL PROTECTED] > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: turbine-jcs-user- > [EMAIL PROTECTED] > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: turbine-jcs-user- > [EMAIL PROTECTED] > > > > > > > --------------------------------------------------------------------- > 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]
