> timasmith@hotmail.com wrote On 07/28/06 15:11,:
> > Hi,
[quoted text clipped - 28 lines]
> of thing that really ought not be repeated. What are
> your objectives?
Exactly, these are expensive calls.
> Second, I'd look for a less clunky key than a String.
> Your example shows a pair of integers; why not write a
> tiny little IntegerPair class and use that instead?
The String *is* clunky but I have dozens of methods, often with a
variety of parameters.
getStaticReference(int i); getStaticReference(int i, int j);
getStaticReference(String s);
getStaticReference2(long l); getStaticReference3(); etc.
I have a feeling something in Java5 with variable method parameters
might help.
> Third, I'd worry about old, stale argument/value
> pairs sitting around clogging up the HashMap long after
[quoted text clipped - 4 lines]
> I've heard vague mention of them and would research them
> if I were planning to implement this sort of thing).
Agreed on the aging, I am weak on the WeakReferences
> Fourth, I'd wonder about that getCallingMethodName()
> thing. I can't think of a way to implement it with
> reasonable efficiency (throwing and catching an exception
> and scrutinizing its stack seems the only way).
Right that is how I did it
More to the
> point, why should I expect the wrapped method to behave
> differently when called from foo() than from bar()?
This problem does not occur - above the getCallingMethodName() looks
at the right and only method - which is the one calling getKey - if it
is a different calling method then it needs a different cached result
And
> if it behaves the same, why shouldn't I return the same
> value to bar() that was computed and cached on behalf
[quoted text clipped - 4 lines]
> That's not to say I'd completely rule out caching, just
> that I'd be very cautious about it ...
Mmm, good point, they are not meant to be mutable but I would have to
put something in place to make that so (I trust noone...)
I still think I am reinventing the wheel or if not a wheel perhaps a
database component.
Eric Sosman - 29 Jul 2006 02:21 GMT
>>timasmith@hotmail.com wrote On 07/28/06 15:11,:
>>
[quoted text clipped - 10 lines]
> getStaticReference(String s);
> getStaticReference2(long l); getStaticReference3(); etc.
Use a separate cache for each. This will also obviate the
mucking about with trying to get the name of the calling method.

Signature
Eric Sosman
esosman@acm-dot-org.invalid
timasmith@hotmail.com - 29 Jul 2006 03:49 GMT
> >>timasmith@hotmail.com wrote On 07/28/06 15:11,:
> >>
[quoted text clipped - 17 lines]
> Eric Sosman
> esosman@acm-dot-org.invalid
Now thats very nice, thanks for the tip!
Hendrik Maryns - 31 Jul 2006 12:11 GMT
>> Third, I'd worry about old, stale argument/value
>> pairs sitting around clogging up the HashMap long after
[quoted text clipped - 6 lines]
>
> Agreed on the aging, I am weak on the WeakReferences
Have a look at ReferenceMap in Jakarta Commons Collections, it does
exactly what you want. Not that I am sure this is going the right way,
btw. Are you trying to use dynamic programming? Usually, matrices with
strictly defined semantics are used there.
H.
- --
Hendrik Maryns
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html