Back Forum Reply New

Spring 3.1 Cache Abstraction: How do I switch the KeyGenerator?

Hello everybody,

I have a String as a key in my cache. Since the DefaultKeyGenerator uses hashCode() for generating the key I cannot use it, because there may be collisions.

It's no problem to provide another implementation of KeyGenerator, but I'm missing a simple way to use it. There is no such attribute on lt;cache:annotation-driven/gt; nor on CacheManager nor on Cache, just on the Aspect itself, but I don't wanna declare it myself.

Can somebody help me?

Tobias

Okay, still don't know how to switch the default KeyGenerator implementation, but I realized that I don't really need it when I use the key attribute on the @Cacheable annotation.

By the way, there is an error in the reference documentation. You need to reference the parameter with a hash: key=quot;#parameternamequot;, otherwise Spel is trying to find a property parametername on some helper class.

Another problem with Default implementation, it's calculating hashCode of method param, but doesn't include methodName in calculations.
I remember reading documentation, hashCode is combination of methodName + params.
¥
Back Forum Reply New