Announcement Announcement Module

Spring Modules forum decommissioned in favor of Spring Extensions

As the Spring Modules project has been replaced by the Spring Extensions ( project, this forum has been decommissioned in favour of Spring Extensions one at:

Please see the Spring Extensions home page for a complete list of current projects in Java, .NET and ActionScript. You can also propose one if you want.

Costin Leau
SpringSource - Spring Training, Consulting, and Support - "From the Source"
See more
See less
In regards to cloning of the SpringModules Caching project. Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • In regards to cloning of the SpringModules Caching project.

    I noticed that the SpringModules Cache project has become rather stale in the last year and a half. I know there's a fair number of users out there would have submitted bugs and feature enhancements, so I figured it's time for someone to take ownership of this project. Today I cloned the CVS repository and made some basic changes which I will release shortly. For those interested in what changes they can expect, I'll provide a rough overview of what to expect.

    1. The project has been split up into multiple projects. This will allow users to only include what's needed without downloading all of the dependencies used for compiling the project. There's basically two categories: Core and Providers.
    2. Minor changes to the provider API - I have made some minor changes to the core provider API which will now allow third party caching providers to get direct access to annotations that decorate the Methods.
    3. The Maven artifacts will be released to the central repository.

    If you have any feature enhancements you would like to see, please reply back to this thread. When I am complete my initial changes, I'll make an announcement here on this forum.

    Best Regards,
    Richard L. Burton III
    SmarCode LLC

  • #2
    Great initiative

    Great initiative. We have used SM caching for a while now and have done a bunch of adaptations for it. People including me have written previously here about the hash collision issues. Here is an example of a cache key generator implementation that has two benefits over the existing one in 0.9:

    1. No more hash collisions (ie you will not get wrong/unexpected results back) from cached method calls.

    2. It is possible to derive the exact method call that generated the cache content by looking at the key.

    import java.lang.reflect.Method;
    import java.util.HashMap;
    import java.util.Map;
    import org.aopalliance.intercept.MethodInvocation;
    import org.springmodules.cache.key.CacheKeyGenerator;
    import org.springmodules.cache.key.HashCodeCacheKey;
    import org.springmodules.cache.key.HashCodeCalculator;
    import org.springmodules.cache.util.Reflections;
    import com.thoughtworks.xstream.XStream;
    public class CacheKeyGeneratorImpl implements CacheKeyGenerator {
            private XStream xstream = new XStream(new JettisonMappedXmlDriver());
            public CacheKeyGeneratorImpl() {
            public final Serializable generateKey(MethodInvocation methodInvocation) {
                    StringBuffer sb = new StringBuffer();
                    Method method = methodInvocation.getMethod();
                    Object[] methodArguments = methodInvocation.getArguments();
                    if (methodArguments != null) {
                            int methodArgumentCount = methodArguments.length;
                            for (int i = 0; i < methodArgumentCount; i++) {
                    return sb.toString();
    Last edited by danielh; May 23rd, 2009, 05:10 AM.


    • #3
      I'll put a patch in that'll correct this issue. I want to resolve this without using XStream since it'll impact performance.

      Do you have a test case showing this issue?


      Best Regards,
      Richard L. Burton III


      • #4
        Test case

        Right, XStream is probably not the best in the general case, but it worked in out case. Let me know if you need a more "formalized" JUnit like test case.

        import java.util.*;
        import java.lang.reflect.*;
        import org.springmodules.cache.key.*;
        import org.aopalliance.intercept.MethodInvocation;
        public class Test {
            public static void main(String[] args) {
        	try {
        	    new Test().test();
        	} catch (Exception e) {
            public void test() throws Exception {
        	Long arg1 = (long) Math.pow(2.0, 32.0);
        	Long arg2 = 1L;
        	System.out.println("arg1.equals(arg2) -> " + arg1.equals(arg2));
        	Method methodToCache = Test.class.getDeclaredMethod("someMethodWeWantCached", Object.class);
        	CacheKeyGenerator g = new HashCodeCacheKeyGenerator(true);
        	Serializable key1 = g.generateKey(fakeMethodInvocation(methodToCache, arg1));
        	Serializable key2 = g.generateKey(fakeMethodInvocation(methodToCache, arg2));
        	System.out.println("key1.equals(key2) -> " + key1.equals(key2));
            private MethodInvocation fakeMethodInvocation(final Method methodToCache, final Object arg) {
        	return new MethodInvocation() {
        		public Method getMethod() {
        		    return methodToCache;
        		public Object[] getArguments() {
        		    return new Object[] { arg };
        		public Object getThis() {
        		    return Test.this;
        		public AccessibleObject getStaticPart() {
        		    return null;
        		public Object proceed() throws Throwable {
        		    return null;
            public Object someMethodWeWantCached(Object o) {
        	return o;


        • #5
          This is great! I'll create a fix for this and put it in the release.

          I'll keep everyone updated on this thread. I need to find a place to host this.. hmmm


          • #6
            Kudos for picking this up again,
            Did you find a host yet? I'd love access to this right now and the entire springmodules site is just sooooo slow. also if there are improvements to be had that dont live in their cvs I definitely want them.
            Eagerly awaiting news.


            • #7
              Spring Extensions?

              Have anyone tried moving the cache project to Spring Extensions?


              • #8
                Caching extension

                Originally posted by magott View Post
                Have anyone tried moving the cache project to Spring Extensions?
                I came across this today, however I noticed there is a formal process for submitting it as an extension. Here is the thread where they request extensions. I don't know how valid it is, other than the most popular request is spring caching.


                Richard may have already started down the process to make it an extension.


                • #9
                  Where is the project

                  Maybe I'm missing something obvious, I'm unable to find this project source, can someone point me in the right direction, I thought it would be in the spring mod cvs. thanks