@Test public void shouldReturnCachedKeysBeforeExpirationAccountingForAgeHeader() throws Exception { KeysDownloader instance = newInstanceForTests(); httpResponseBuilder = new HttpResponseBuilder() .setContent("keys1") .setCacheControlWithMaxAgeInSeconds(3L) .setAgeInSeconds(1L); assertEquals("keys1", instance.download()); httpResponseBuilder = new HttpResponseBuilder().setContent("keys2"); currentTimeInMillis += 2000L - 1; assertEquals("keys1", instance.download()); }
public String download() throws IOException { synchronized (instanceStateLock) { if (hasNonExpiredDataCached()) { if (shouldProactivelyRefreshDataInBackground()) { refreshInBackground(); } return cachedData; } } synchronized (fetchDataLock) { synchronized (instanceStateLock) { if (hasNonExpiredDataCached()) { return cachedData; } } return fetchAndCacheData(); } }
KeysDownloader { public String download() throws IOException { synchronized (instanceStateLock) { if (hasNonExpiredDataCached()) { if (shouldProactivelyRefreshDataInBackground()) { refreshInBackground(); } return cachedData; } } synchronized (fetchDataLock) { synchronized (instanceStateLock) { if (hasNonExpiredDataCached()) { return cachedData; } } return fetchAndCacheData(); } } }
KeysDownloader { public String download() throws IOException { synchronized (instanceStateLock) { if (hasNonExpiredDataCached()) { if (shouldProactivelyRefreshDataInBackground()) { refreshInBackground(); } return cachedData; } } synchronized (fetchDataLock) { synchronized (instanceStateLock) { if (hasNonExpiredDataCached()) { return cachedData; } } return fetchAndCacheData(); } } KeysDownloader(Executor backgroundExecutor, HttpTransport httpTransport, String url); }
KeysDownloader { public String download() throws IOException { synchronized (instanceStateLock) { if (hasNonExpiredDataCached()) { if (shouldProactivelyRefreshDataInBackground()) { refreshInBackground(); } return cachedData; } } synchronized (fetchDataLock) { synchronized (instanceStateLock) { if (hasNonExpiredDataCached()) { return cachedData; } } return fetchAndCacheData(); } } KeysDownloader(Executor backgroundExecutor, HttpTransport httpTransport, String url); String download(); HttpTransport getHttpTransport(); String getUrl(); void refreshInBackground(); }
KeysDownloader { public String download() throws IOException { synchronized (instanceStateLock) { if (hasNonExpiredDataCached()) { if (shouldProactivelyRefreshDataInBackground()) { refreshInBackground(); } return cachedData; } } synchronized (fetchDataLock) { synchronized (instanceStateLock) { if (hasNonExpiredDataCached()) { return cachedData; } } return fetchAndCacheData(); } } KeysDownloader(Executor backgroundExecutor, HttpTransport httpTransport, String url); String download(); HttpTransport getHttpTransport(); String getUrl(); void refreshInBackground();  }