Monday, September 20, 2010

Spring, AspectJ, Hazelcast Method Caching Aspect

After my recent discovery of Hazelcast, I decided to update my caching aspect project to include a Hazelcast implementation.

The source code for this project is available here

For more information please refer to the actual source or my original Ehcache post. The main difference here is that the Hazelcast implementation is by default a distributed cache, and takes advantage of all the other functionality that Hazelcast provides.
The main points of interest for this implementation are:
- The actual aspect class. See code below.
- The application context. See xml below.
- The Hazelcast configuration. I am using the default Hazelcast configuration, located in the hazelcast-version.jar. To use a custom one, you can define a hazelcast.xml and inject it via Spring.
- The CacheKeyStrategy in the code below is an interface defined to allow key generation for the cache for specific requirements. There is a default implementation that simply sorts and uses hashcodes of the values in the class. You can define a strategy per type you want to cache.

note: java docs only removed for size of post

The aspect:

The application context:

The test case:


  1. Any idea how this can be done using Guice?

    1. Hi, Guice require source-level access. If the annotation bothers you or you're using Guice to create objects. I found another advance tutorial here, you can see,

      However I love this post also, really appreciate your work. Thanks from -best free ios games

  2. Mmmm... I have never used Guice, just did a quick search and a little bit of reading... I could probably slap it together tomorrow. From what I can see Guice is also using AopAlliance.. and their implementation will be very similar to my original Spring 2.x or even 1.X implementation. You will need to Implement MethodInterceptor ... and use a MethodInvocation object instead of ProceedingJoinPoint.

    If you don't come right, let me know.. shouldn't take long to adapt this version.

  3. Gr8 article. Thx for sharing. I linked up your article from my blog. Hope you do not mind :)... Cheers.


  4. Thank you... and of course I don't mind.


Popular Posts