use of com.netflix.hystrix.contrib.javanica.cache.annotation.CacheRemove in project Hystrix by Netflix.
the class CacheInvocationContextFactoryTest method testCreateCacheRemoveInvocationContext_givenMethodAnnotatedWithCacheRemove_shouldCreateCorrectCacheKeyInvocationContext.
@Test
public void testCreateCacheRemoveInvocationContext_givenMethodAnnotatedWithCacheRemove_shouldCreateCorrectCacheKeyInvocationContext() throws NoSuchMethodException {
// given
TestCacheClass testCacheClass = new TestCacheClass();
String param1 = "val_1";
MetaHolder metaHolder = MetaHolder.builder().method(TestCacheClass.class.getMethod("cacheRemoveMethod", String.class)).args(new Object[] { param1 }).obj(testCacheClass).build();
// when
CacheInvocationContext<CacheRemove> context = CacheInvocationContextFactory.createCacheRemoveInvocationContext(metaHolder);
// then
assertNotNull(context.getKeyParameters());
assertEquals(1, context.getKeyParameters().size());
CacheInvocationParameter actual = context.getKeyParameters().get(0);
assertEquals(String.class, actual.getRawType());
assertEquals(param1, actual.getValue());
assertEquals(0, actual.getPosition());
}
use of com.netflix.hystrix.contrib.javanica.cache.annotation.CacheRemove in project Hystrix by Netflix.
the class CacheInvocationContextFactory method createCacheRemoveInvocationContext.
/**
* Create {@link CacheInvocationContext} parametrized with {@link CacheRemove} annotation.
*
* @param metaHolder the meta holder, see {@link com.netflix.hystrix.contrib.javanica.command.MetaHolder}
* @return initialized and configured {@link CacheInvocationContext}
*/
public static CacheInvocationContext<CacheRemove> createCacheRemoveInvocationContext(MetaHolder metaHolder) {
Method method = metaHolder.getMethod();
if (method.isAnnotationPresent(CacheRemove.class)) {
CacheRemove cacheRemove = method.getAnnotation(CacheRemove.class);
MethodExecutionAction cacheKeyMethod = createCacheKeyAction(cacheRemove.cacheKeyMethod(), metaHolder);
return new CacheInvocationContext<CacheRemove>(cacheRemove, cacheKeyMethod, metaHolder.getObj(), method, metaHolder.getArgs());
}
return null;
}
use of com.netflix.hystrix.contrib.javanica.cache.annotation.CacheRemove in project Hystrix by Netflix.
the class HystrixCacheAspect method methodsAnnotatedWithCacheRemove.
@Around("cacheRemoveAnnotationPointcut()")
public Object methodsAnnotatedWithCacheRemove(final ProceedingJoinPoint joinPoint) throws Throwable {
Method method = getMethodFromTarget(joinPoint);
Object obj = joinPoint.getTarget();
Object[] args = joinPoint.getArgs();
Validate.notNull(method, "failed to get method from joinPoint: %s", joinPoint);
MetaHolder metaHolder = MetaHolder.builder().args(args).method(method).obj(obj).executionType(ExecutionType.SYNCHRONOUS).ajcMethod(isCompileWeaving() ? getAjcMethodAroundAdvice(obj.getClass(), method) : null).build();
CacheInvocationContext<CacheRemove> context = CacheInvocationContextFactory.createCacheRemoveInvocationContext(metaHolder);
HystrixRequestCacheManager.getInstance().clearCache(context);
return joinPoint.proceed();
}
Aggregations