View Javadoc
1   package org.springframework.cache.jcache.support;
2   
3   import java.lang.annotation.Annotation;
4   import javax.cache.annotation.CacheKeyGenerator;
5   import javax.cache.annotation.CacheKeyInvocationContext;
6   import javax.cache.annotation.GeneratedCacheKey;
7   
8   import org.springframework.cache.interceptor.SimpleKey;
9   
10  /**
11   * A simple test key generator that only takes the first key arguments into
12   * account. To be used with a multi parameters key to validate it has been
13   * used properly.
14   *
15   * @author Stephane Nicoll
16   */
17  public class TestableCacheKeyGenerator implements CacheKeyGenerator {
18  
19  	@Override
20  	public GeneratedCacheKey generateCacheKey(CacheKeyInvocationContext<? extends Annotation> context) {
21  		return new SimpleGeneratedCacheKey(context.getKeyParameters()[0]);
22  	}
23  
24  
25  	@SuppressWarnings("serial")
26  	private static class SimpleGeneratedCacheKey extends SimpleKey implements GeneratedCacheKey {
27  
28  		public SimpleGeneratedCacheKey(Object... elements) {
29  			super(elements);
30  		}
31  
32  	}
33  
34  }