test_class.file: guja-core/src/test/java/com/wadpam/guja/cache/annotations/CacheResultMethodInterceptorTest.java
test_class.identifier: CacheResultMethodInterceptorTest
test_class.superclass: extends AbstractCacheMethodInterceptorTest
test_case.body: @Test
    public void testInvoke() throws Exception {
      final String parentKey = null;
  
      expect(mockDao.get(parentKey, 1L)).andReturn("1").once();
      expect(mockDao.get(parentKey, 2L)).andReturn("2").once();
  
      replay(mockDao);
  
      String value = dao.get(parentKey, 1L);
      assertTrue("1".equals(value));
  
      value = dao.get(parentKey, 1L);
      assertTrue("1".equals(value));
  
      value = dao.get(parentKey, 2L);
      assertTrue("2".equals(value));
    }
test_case.class_method_signature: CacheResultMethodInterceptorTest.testInvoke()
test_case.full_signature: @Test public void testInvoke()
test_case.identifier: testInvoke
test_case.invocations: once andReturn expect get once andReturn expect get replay get assertTrue equals get assertTrue equals get assertTrue equals
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testInvoke()
focal_class.declarator: LOGGER = LoggerFactory.getLogger(CacheResultMethodInterceptor.class)
focal_class.modifier: static final
focal_class.original_string: static final Logger LOGGER = LoggerFactory.getLogger(CacheResultMethodInterceptor.class);
focal_class.type: Logger
focal_class.var_name: LOGGER
focal_class.file: guja-core/src/main/java/com/wadpam/guja/cache/annotations/CacheResultMethodInterceptor.java
focal_class.identifier: CacheResultMethodInterceptor
focal_class.class_method_signature: CacheResultMethodInterceptor.CacheResultMethodInterceptor(Provider<CacheResolver> cacheResolverProvider, Provider<CacheKeyGenerator> defaultCacheKeyGeneratorProvider)
focal_class.full_signature: @Inject public  CacheResultMethodInterceptor(Provider<CacheResolver> cacheResolverProvider, Provider<CacheKeyGenerator> defaultCacheKeyGeneratorProvider)
focal_class.identifier: CacheResultMethodInterceptor
focal_class.modifiers: @Inject public
focal_class.parameters: (Provider<CacheResolver> cacheResolverProvider, Provider<CacheKeyGenerator> defaultCacheKeyGeneratorProvider)
focal_class.signature:  CacheResultMethodInterceptor(Provider<CacheResolver> cacheResolverProvider, Provider<CacheKeyGenerator> defaultCacheKeyGeneratorProvider)
focal_class.class_method_signature: CacheResultMethodInterceptor.invoke(final MethodInvocation methodInvocation)
focal_class.full_signature: @Override public Object invoke(final MethodInvocation methodInvocation)
focal_class.identifier: invoke
focal_class.modifiers: @Override public
focal_class.parameters: (final MethodInvocation methodInvocation)
focal_class.return: Object
focal_class.signature: Object invoke(final MethodInvocation methodInvocation)
focal_class.superclass: extends AbstractCacheMethodInterceptor
focal_method.body: @Override
    public Object invoke(final MethodInvocation methodInvocation) throws Throwable {
  
      final Method method = methodInvocation.getMethod();
      final CacheResult annotation = method.getAnnotation(CacheResult.class);
      checkNotNull(annotation);
      final CacheKeyInvocationContext<CacheResult> context = new GuiceCacheKeyInvocationContext<>(methodInvocation, annotation, annotation.cacheName());
  
      LOGGER.debug("Cache RESULT {}", context.getMethod().getName());
  
      // get cache
      final Cache<GeneratedCacheKey, Optional<?>> cache = getCache(context, methodInvocation);
  
      // get key
      final CacheKeyGenerator keyGenerator = getCacheKeyGenerator(methodInvocation, annotation.cacheKeyGenerator());
      final GeneratedCacheKey key = keyGenerator.generateCacheKey(context);
  
      Object result;
      if(!annotation.skipGet()) {
  
        Optional<?> value = cache.get(key, new Callable<Optional<?>>() {
          @Override
          public Optional<?> call() throws Exception {
            LOGGER.trace("Loading for {}({})", method.getName(), key);
            try {
              final Object value = methodInvocation.proceed();
              return null != value ? Optional.of(value) : Optional.absent();
            } catch (Throwable throwable) {
              LOGGER.error("Failed to populate cache {} {}", method.getName(), throwable);
              throw new ExecutionException("During invocation: ", throwable);
            }
          }
        });
  
        return value.isPresent() ? value.get() : null;
      }
  
      // Always run the annotated method and update the cache
      result = methodInvocation.proceed();
      cache.put(key, null != result ? Optional.of(result) : Optional.absent());
      return result;
  
    }
focal_method.class_method_signature: CacheResultMethodInterceptor.invoke(final MethodInvocation methodInvocation)
focal_method.full_signature: @Override public Object invoke(final MethodInvocation methodInvocation)
focal_method.identifier: invoke
focal_method.invocations: getMethod getAnnotation checkNotNull cacheName debug getName getMethod getCache getCacheKeyGenerator cacheKeyGenerator generateCacheKey skipGet get trace getName proceed of absent error getName isPresent get proceed put of absent
focal_method.modifiers: @Override public
focal_method.parameters: (final MethodInvocation methodInvocation)
focal_method.return: Object
focal_method.signature: Object invoke(final MethodInvocation methodInvocation)