Make sure there are no race conditions where etag is known but content just timed out thus resulting in a null response and no cached value to fall back on

This commit is contained in:
Reinhard Pointner 2016-04-12 07:31:26 +00:00
parent 580657aed0
commit eecd53a87d
1 changed files with 2 additions and 2 deletions

View File

@ -300,9 +300,9 @@ public class TMDbClient implements MovieIdentificationService {
String cacheName = locale.getLanguage().isEmpty() ? getName() : getName() + "_" + locale; String cacheName = locale.getLanguage().isEmpty() ? getName() : getName() + "_" + locale;
Cache etagStorage = Cache.getCache(cacheName + "_etag", CacheType.Monthly); Cache etagStorage = Cache.getCache(cacheName + "_etag", CacheType.Monthly);
Fetch fetchIfNoneMatch = fetchIfNoneMatch(url -> etagStorage.get(key), (url, etag) -> etagStorage.put(key, etag));
Cache cache = Cache.getCache(cacheName, CacheType.Monthly); Cache cache = Cache.getCache(cacheName, CacheType.Monthly);
Fetch fetchIfNoneMatch = fetchIfNoneMatch(url -> cache.get(key) == null ? null : etagStorage.get(key), (url, etag) -> etagStorage.put(key, etag));
Object json = cache.json(key, s -> getResource(s, locale)).fetch(withPermit(fetchIfNoneMatch, r -> limit.acquirePermit())).expire(Cache.ONE_WEEK).get(); Object json = cache.json(key, s -> getResource(s, locale)).fetch(withPermit(fetchIfNoneMatch, r -> limit.acquirePermit())).expire(Cache.ONE_WEEK).get();
if (asMap(json).isEmpty()) { if (asMap(json).isEmpty()) {