-
Apr 3rd, 2009, 07:07 PM
#1
EhCache declarative caching hash collision issues
Hi,
I am using EhCacheFacade for declarative caching. Recently, I noticed that even the first invocation of some methods were being returned from the cache, without calling the method at all.
On digging deeper I found that when hashcode() matches for input arguments for a method, the input arguments are assumed to be equal. So, when there is a hash collision on input arguments across different method invocations, the method invocation are assumed to be the same.
For eg: Lets have a function - int foobar(Foo f, Bar b);
For two invocations of foobar --
Invocation 1 - foobar(f1, b1)
Invocation 2 - foobar(f2, b2)
If f1.hashcode() == f2.hashcode() and b1.hashcode() == b2.hashcode() [even though f1 not equal to f2, and b1 not equal to b2] - the caching module assumes both invocations are the same. Hence it returns the cached version of Invocation 1 when Invocation 2 happens.
Has anyone else encountered the above issue? Any reason why the caching module is not taking care of hash collisions, or am I missing something here?
Thanks.
-
Apr 23rd, 2009, 04:31 PM
#2
Noticed it too
Yes I just noticed this too. Pretty scary. I am looking into replacing HashCodeCacheKeyGenerator with my own implementation.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules