EtagCache implements Flushable { public EtagCache resetStats() { hits.set(0); misses.set(0); return this; } EtagCache(final File file, final long size); static EtagCache create(final File file, final long size); int getHits(); int getMisses(); long getSize(); EtagCache resetStats(); CacheResponse get(final URLConnection connection); InputStream put(final URLConnection connection); InputStream put(final URLConnection connection,
      final boolean flushCacheOnClose); void flush(); static final long ONE_MB; static final long FIVE_MB; static final long TEN_MB; }
@Test public void resetStats() throws Exception { String url = setUp(new RequestHandler() { @Override public void handle(Request request, HttpServletResponse response) { response.setHeader(HEADER_ETAG, "1234"); if ("1234".equals(request.getHeader(HEADER_IF_NONE_MATCH))) response.setStatus(HTTP_NOT_MODIFIED); else { write("hello"); response.setStatus(HTTP_OK); } } }); File file = File.createTempFile("cache", ".dir"); assertTrue(file.delete()); assertTrue(file.mkdirs()); EtagCache cache = EtagCache.create(file, ONE_MB); assertNotNull(cache); assertEquals(0, cache.getHits()); assertEquals(0, cache.getMisses()); CacheRequest request = CacheRequest.get(url, cache); assertTrue(request.ok()); request.body(); assertEquals(0, cache.getHits()); assertEquals(1, cache.getMisses()); request = CacheRequest.get(url, cache); assertTrue(request.ok()); assertEquals("hello", request.body()); assertTrue(request.cached()); assertEquals(1, cache.getHits()); assertEquals(1, cache.getMisses()); cache.resetStats(); assertEquals(0, cache.getHits()); assertEquals(0, cache.getMisses()); }