public Value get( Key key ) throws Exception {
    ActiveCacheResult<Value> result = null;
    Future<ActiveCacheResult<Value>> futureResult = null;
    synchronized ( this ) {
      result = valueMap.get( key );
      boolean shouldReload = false;
      long time = System.currentTimeMillis();
      if ( result == null || result.getTimeLoaded() + timeout < time ) {
        // Expired, we need to wait on reload
        result = null;
        shouldReload = true;
      } else if ( result.getTimeLoaded() + ( timeout / 2.0 ) < time ) {
        // Preemptively reload
        shouldReload = true;
      }
      if ( shouldReload ) {
        futureResult = loadingMap.get( key );
        if ( futureResult == null ) {
          futureResult =
              executorServiceGetter.getExecutor().submit(
                  new ActiveCacheCallable<Key, Value>( this, valueMap, loadingMap, key, loader ) );
          loadingMap.put( key, futureResult );
        }
      }
    }
    if ( result == null ) {
      result = futureResult.get();
    }
    Exception exception = result.getException();
    if ( exception != null ) {
      throw exception;
    }
    return result.getValue();
  }
@Test
  public void testActiveCacheLoadsWhenNull() throws Exception {
    long timeout = 100;
    @SuppressWarnings( "unchecked" )
    ActiveCacheLoader<String, String> mockLoader = mock( ActiveCacheLoader.class );
    ActiveCache<String, String> cache = new ActiveCache<String, String>( mockLoader, timeout );
    String testKey = "TEST-KEY";
    String testResult = "TEST-RESULT";
    when( mockLoader.load( testKey ) ).thenReturn( testResult );
    assertEquals( testResult, cache.get( testKey ) );
    verify( mockLoader, times( 1 ) ).load( testKey );
  }