From eecd53a87dc3f2892bf6ddd9c54f180ab0ccb0b0 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Tue, 12 Apr 2016 07:31:26 +0000 Subject: [PATCH] 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 --- source/net/filebot/web/TMDbClient.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/net/filebot/web/TMDbClient.java b/source/net/filebot/web/TMDbClient.java index 28a47b05..35203598 100644 --- a/source/net/filebot/web/TMDbClient.java +++ b/source/net/filebot/web/TMDbClient.java @@ -300,9 +300,9 @@ public class TMDbClient implements MovieIdentificationService { String cacheName = locale.getLanguage().isEmpty() ? getName() : getName() + "_" + locale; 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); + + 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(); if (asMap(json).isEmpty()) {