CacheableMethodKeyFactoryManager { public CacheableMethodKeyFactory getCacheableMethodKeyFactoryForMethod( Method m) { Cacheable cacheableAnnotation = m.getAnnotation(Cacheable.class); if (cacheableAnnotation != null) { Class<? extends CacheableMethodKeyFactory> keyFactoryType = cacheableAnnotation.keyFactory(); if (!keyFactoryType.equals(CacheableMethodKeyFactory.class)) try { return keyFactoryType.newInstance(); } catch (Exception ex) { throw new IllegalStateException( "error instantiating CacheableKeyFactory: " + keyFactoryType.getName(), ex); } } Class<?>[] parameters = m.getParameterTypes(); Annotation[][] annotations = m.getParameterAnnotations(); int cacheRefreshParameterIndex = -1; if (_cacheRefreshIndicatorArgumentIndexByMethod.containsKey(m)) cacheRefreshParameterIndex = _cacheRefreshIndicatorArgumentIndexByMethod.get(m); CacheableObjectKeyFactory[] keyFactories = new CacheableObjectKeyFactory[parameters.length]; for (int i = 0; i < parameters.length; i++) { boolean cacheRefreshIndicator = (i == cacheRefreshParameterIndex); CacheableArgument cacheableArgumentAnnotation = getCacheableArgumentAnnotation(annotations[i]); if (cacheableArgumentAnnotation != null) { keyFactories[i] = getKeyFactoryForCacheableArgumentAnnotation( parameters[i], cacheableArgumentAnnotation, cacheRefreshIndicator); } else { keyFactories[i] = getKeyFactoryForParameterType(parameters[i], cacheRefreshIndicator); } } return new DefaultCacheableKeyFactory(keyFactories); }  void addCacheableObjectKeyFactory(Class<?> className,
      CacheableObjectKeyFactory keyFactory); void setCacheKeyFactories(Map<Object, Object> keyFactories); void putCacheRefreshIndicatorArgumentIndexForMethodSignature(
      String methodName, int argumentIndex); void putCacheRefreshIndicatorArgumentIndexForMethod(Method method,
      int argumentIndex); CacheableMethodKeyFactory getCacheableMethodKeyFactoryForJoinPoint(
      ProceedingJoinPoint pjp, Method method); CacheableMethodKeyFactory getCacheableMethodKeyFactoryForMethod(
      Method m); Method getMatchingMethodForJoinPoint(ProceedingJoinPoint pjp); List<Method> getMatchingMethodsForJoinPoint(ProceedingJoinPoint pjp);  }
@Test public void testServiceMethod01() throws SecurityException, NoSuchMethodException { Method method = MockServiceImpl.class.getMethod("evalaute", String.class); CacheableMethodKeyFactoryManager manager = new CacheableMethodKeyFactoryManager(); CacheableMethodKeyFactory factory = manager.getCacheableMethodKeyFactoryForMethod(method); assertTrue(factory instanceof DefaultCacheableKeyFactory); DefaultCacheableKeyFactory defaultFactory = (DefaultCacheableKeyFactory) factory; assertEquals(1, defaultFactory.getNumberOfObjectKeyFactories()); CacheableObjectKeyFactory objectKeyFactory = defaultFactory.getObjectKeyFactory(0); assertTrue(objectKeyFactory instanceof DefaultCacheableObjectKeyFactory); DefaultCacheableObjectKeyFactory defaultObjectKeyFactory = (DefaultCacheableObjectKeyFactory) objectKeyFactory; assertFalse(defaultObjectKeyFactory.isCacheRefreshCheck()); }
@Test public void testServiceMethod02() throws SecurityException, NoSuchMethodException { Method method = MockServiceImpl.class.getMethod("evalauteBean", MockBean.class); CacheableMethodKeyFactoryManager manager = new CacheableMethodKeyFactoryManager(); CacheableMethodKeyFactory factory = manager.getCacheableMethodKeyFactoryForMethod(method); assertTrue(factory instanceof DefaultCacheableKeyFactory); DefaultCacheableKeyFactory defaultFactory = (DefaultCacheableKeyFactory) factory; assertEquals(1, defaultFactory.getNumberOfObjectKeyFactories()); CacheableObjectKeyFactory objectKeyFactory = defaultFactory.getObjectKeyFactory(0); assertTrue(objectKeyFactory instanceof DefaultCacheableObjectKeyFactory); DefaultCacheableObjectKeyFactory defaultObjectKeyFactory = (DefaultCacheableObjectKeyFactory) objectKeyFactory; assertFalse(defaultObjectKeyFactory.isCacheRefreshCheck()); }
@Test public void testServiceMethod03() throws SecurityException, NoSuchMethodException { Method method = MockServiceImpl.class.getMethod( "evalauteBeanWithAnnotation", MockBean.class); CacheableMethodKeyFactoryManager manager = new CacheableMethodKeyFactoryManager(); CacheableMethodKeyFactory factory = manager.getCacheableMethodKeyFactoryForMethod(method); assertTrue(factory instanceof MockCacheableMethodKeyFactory); }
@Test public void testServiceMethod04() throws SecurityException, NoSuchMethodException { Method method = MockServiceImpl.class.getMethod( "evalauteBeanWithParameterAnnotation", MockBean.class, Boolean.TYPE); CacheableMethodKeyFactoryManager manager = new CacheableMethodKeyFactoryManager(); CacheableMethodKeyFactory factory = manager.getCacheableMethodKeyFactoryForMethod(method); assertTrue(factory instanceof DefaultCacheableKeyFactory); DefaultCacheableKeyFactory defaultFactory = (DefaultCacheableKeyFactory) factory; assertEquals(2, defaultFactory.getNumberOfObjectKeyFactories()); CacheableObjectKeyFactory objectKeyFactoryA = defaultFactory.getObjectKeyFactory(0); assertTrue(objectKeyFactoryA instanceof PropertyPathExpressionCacheableObjectKeyFactory); CacheableObjectKeyFactory objectKeyFactoryB = defaultFactory.getObjectKeyFactory(1); assertTrue(objectKeyFactoryB instanceof DefaultCacheableObjectKeyFactory); DefaultCacheableObjectKeyFactory defaultObjectKeyFactoryB = (DefaultCacheableObjectKeyFactory) objectKeyFactoryB; assertTrue(defaultObjectKeyFactoryB.isCacheRefreshCheck()); }