CachedGauge implements Gauge<T> { public T getValue() { if (shouldLoad()) { this.value = loadValue(); lastUpdate = System.currentTimeMillis(); } return value; } protected  CachedGauge(long timeout, TimeUnit timeoutUnit); protected  CachedGauge(Clock clock, long timeout, TimeUnit timeoutUnit); T getValue(); @Override long lastUpdateTime();  }
@Test public void reloadsTheCachedValueAfterTheGivenPeriod() throws Exception { assertThat(gauge.getValue()) .isEqualTo(1); Thread.sleep(150); assertThat(gauge.getValue()) .isEqualTo(2); assertThat(gauge.getValue()) .isEqualTo(2); }