@Test public void testInvoke() throws Exception { final String parentKey = null; expect(mockDao.put(parentKey, 1L, "1")).andReturn(1L).once(); expect(mockDao.get(parentKey, 1L)).andReturn(null).once(); expect(mockDao.put(parentKey, 1L, "1")).andReturn(1L).once(); replay(mockDao); Long id = dao.put(parentKey, 1L, "1"); assertTrue(id.equals(1L)); String value = dao.get(parentKey, 1L); assertTrue("1".equals(value)); dao.removeAll(); value = dao.get(parentKey, 1L); assertTrue(null == value); value = dao.get(parentKey, 1L); assertTrue(null == value); id = dao.put(parentKey, 1L, "1"); assertTrue(id.equals(1L)); value = dao.get(parentKey, 1L); assertTrue("1".equals(value)); }
@Override public Object invoke(MethodInvocation methodInvocation) throws Throwable { final Method method = methodInvocation.getMethod(); final CacheRemoveAll annotation = method.getAnnotation(CacheRemoveAll.class); checkNotNull(annotation); final CacheKeyInvocationContext<CacheRemoveAll> context = new GuiceCacheKeyInvocationContext<>(methodInvocation, annotation, annotation.cacheName()); LOGGER.trace("Cache REMOVE_ALL {}", context.getMethod().getName()); final Cache<GeneratedCacheKey, Optional<?>> cache = getCache(context, methodInvocation); if (!annotation.afterInvocation()) { cache.invalidateAll(); } final Object result = methodInvocation.proceed(); if (annotation.afterInvocation()) { cache.invalidateAll(); } return result; }
CacheRemoveAllMethodInterceptor extends AbstractCacheMethodInterceptor { @Override public Object invoke(MethodInvocation methodInvocation) throws Throwable { final Method method = methodInvocation.getMethod(); final CacheRemoveAll annotation = method.getAnnotation(CacheRemoveAll.class); checkNotNull(annotation); final CacheKeyInvocationContext<CacheRemoveAll> context = new GuiceCacheKeyInvocationContext<>(methodInvocation, annotation, annotation.cacheName()); LOGGER.trace("Cache REMOVE_ALL {}", context.getMethod().getName()); final Cache<GeneratedCacheKey, Optional<?>> cache = getCache(context, methodInvocation); if (!annotation.afterInvocation()) { cache.invalidateAll(); } final Object result = methodInvocation.proceed(); if (annotation.afterInvocation()) { cache.invalidateAll(); } return result; } }
CacheRemoveAllMethodInterceptor extends AbstractCacheMethodInterceptor { @Override public Object invoke(MethodInvocation methodInvocation) throws Throwable { final Method method = methodInvocation.getMethod(); final CacheRemoveAll annotation = method.getAnnotation(CacheRemoveAll.class); checkNotNull(annotation); final CacheKeyInvocationContext<CacheRemoveAll> context = new GuiceCacheKeyInvocationContext<>(methodInvocation, annotation, annotation.cacheName()); LOGGER.trace("Cache REMOVE_ALL {}", context.getMethod().getName()); final Cache<GeneratedCacheKey, Optional<?>> cache = getCache(context, methodInvocation); if (!annotation.afterInvocation()) { cache.invalidateAll(); } final Object result = methodInvocation.proceed(); if (annotation.afterInvocation()) { cache.invalidateAll(); } return result; } @Inject  CacheRemoveAllMethodInterceptor(Provider<CacheResolver> cacheResolverProvider, Provider<CacheKeyGenerator> defaultCacheKeyGeneratorProvider); }
CacheRemoveAllMethodInterceptor extends AbstractCacheMethodInterceptor { @Override public Object invoke(MethodInvocation methodInvocation) throws Throwable { final Method method = methodInvocation.getMethod(); final CacheRemoveAll annotation = method.getAnnotation(CacheRemoveAll.class); checkNotNull(annotation); final CacheKeyInvocationContext<CacheRemoveAll> context = new GuiceCacheKeyInvocationContext<>(methodInvocation, annotation, annotation.cacheName()); LOGGER.trace("Cache REMOVE_ALL {}", context.getMethod().getName()); final Cache<GeneratedCacheKey, Optional<?>> cache = getCache(context, methodInvocation); if (!annotation.afterInvocation()) { cache.invalidateAll(); } final Object result = methodInvocation.proceed(); if (annotation.afterInvocation()) { cache.invalidateAll(); } return result; } @Inject  CacheRemoveAllMethodInterceptor(Provider<CacheResolver> cacheResolverProvider, Provider<CacheKeyGenerator> defaultCacheKeyGeneratorProvider); @Override Object invoke(MethodInvocation methodInvocation); }
CacheRemoveAllMethodInterceptor extends AbstractCacheMethodInterceptor { @Override public Object invoke(MethodInvocation methodInvocation) throws Throwable { final Method method = methodInvocation.getMethod(); final CacheRemoveAll annotation = method.getAnnotation(CacheRemoveAll.class); checkNotNull(annotation); final CacheKeyInvocationContext<CacheRemoveAll> context = new GuiceCacheKeyInvocationContext<>(methodInvocation, annotation, annotation.cacheName()); LOGGER.trace("Cache REMOVE_ALL {}", context.getMethod().getName()); final Cache<GeneratedCacheKey, Optional<?>> cache = getCache(context, methodInvocation); if (!annotation.afterInvocation()) { cache.invalidateAll(); } final Object result = methodInvocation.proceed(); if (annotation.afterInvocation()) { cache.invalidateAll(); } return result; } @Inject  CacheRemoveAllMethodInterceptor(Provider<CacheResolver> cacheResolverProvider, Provider<CacheKeyGenerator> defaultCacheKeyGeneratorProvider); @Override Object invoke(MethodInvocation methodInvocation);  }