FileCacheDataLoader implements DataLoader, DSSFileLoader { public void setCacheExpirationTime(long cacheExpirationTimeInMilliseconds) { this.cacheExpirationTime = cacheExpirationTimeInMilliseconds; } FileCacheDataLoader();  FileCacheDataLoader(DataLoader dataLoader); DataLoader getDataLoader(); void setDataLoader(DataLoader dataLoader); void setFileCacheDirectory(final File fileCacheDirectory); void setCacheExpirationTime(long cacheExpirationTimeInMilliseconds); void setResourceLoader(final ResourceLoader resourceLoader); void addToBeLoaded(final String url); void addToBeIgnored(final String urlString); @Override byte[] get(final String url, final boolean refresh); @Override byte[] get(final String url); @Override DSSDocument getDocument(String url); @Override boolean remove(String url); File createFile(final String urlString, final byte[] bytes); byte[] loadFileFromCache(final String urlString); @Override byte[] post(final String urlString, final byte[] content); @Override DataAndUrl get(final List<String> urlStrings); @Override void setContentType(String contentType);  }
@Test public void getUrl_whenCacheIsNotExpired_useCachedFile() throws Exception { dataLoader.setCacheExpirationTime(2000L); long cacheCreationTime = getUrlAndReturnCacheCreationTime(); waitOneSecond(); long newCacheCreationTime = getUrlAndReturnCacheCreationTime(); assertEquals(cacheCreationTime, newCacheCreationTime); getDSSDocumentByUrl(); }
@Test public void getUrl_whenCacheIsExpired_downloadNewCopy() throws Exception { dataLoader.setCacheExpirationTime(500L); long cacheCreationTime = getUrlAndReturnCacheCreationTime(); waitOneSecond(); long newCacheCreationTime = getUrlAndReturnCacheCreationTime(); assertTrue(cacheCreationTime < newCacheCreationTime); getDSSDocumentByUrl(); }