title: Guava Ticker Cache expire
body: <p>Google Guava tutorial said cache expiration can be tested with <a href="http://docs.guava-libraries.googlecode.com/git-history/release/javadoc/com/google/common/base/Ticker.html" rel="noreferrer">Ticker</a></p>
  
  <p>as my understanding, I can use it to force a quick expiration. <strong>am I right</strong>?</p>
  
  <p>but I tried in the following code, and it did not work, any suggestion?</p>
  
  <pre class="lang-java prettyprint-override"><code>@Test
  public void expireAfterWriteTestWithTicker() throws InterruptedException {
      Ticker t = new Ticker() {
          @Override
          public long read() {
              return TimeUnit.MILLISECONDS.toNanos(5);
          }
      };
      //Use ticker to force expire in 5 millseconds
      LoadingCache&lt;String, String&gt; cache = CacheBuilder.newBuilder()
              .expireAfterWrite(20, TimeUnit.MINUTES).ticker(t).build(loader);
  
      cache.getUnchecked("hello");
      assertEquals(1, cache.size());
      assertNotNull(cache.getIfPresent("hello"));
      //sleep
      Thread.sleep(10);
      assertNull(cache.getIfPresent("hello"));    //failed 
  
  }
  </code></pre>