From ff422c39fa00d30a21b1c64a915d0c4c69054882 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Mon, 10 Jun 2019 21:02:07 +0700 Subject: [PATCH] Initialize etag cache on demand --- source/net/filebot/CachedResource.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/net/filebot/CachedResource.java b/source/net/filebot/CachedResource.java index fef0a58b..017053e6 100644 --- a/source/net/filebot/CachedResource.java +++ b/source/net/filebot/CachedResource.java @@ -221,18 +221,18 @@ public class CachedResource implements Resource { public static Fetch fetchIfNoneMatch(Transform key, Cache cache) { // create cache with the same config - Cache etagStorage = Cache.getCache(cache.getName() + "_etag", cache.getCacheType()); + Resource etagStorage = Resource.lazy(() -> Cache.getCache(cache.getName() + "_etag", cache.getCacheType())); // make sure value cache contains key, otherwise ignore previously stored etag return fetchIfNoneMatch(url -> { try { - return cache.get(key.transform(url)) == null ? null : etagStorage.get(key.transform(url)); + return cache.get(key.transform(url)) == null ? null : etagStorage.get().get(key.transform(url)); } catch (Exception e) { throw new RuntimeException(e); } }, (url, etag) -> { try { - etagStorage.put(key.transform(url), etag); + etagStorage.get().put(key.transform(url), etag); } catch (Exception e) { throw new RuntimeException(e); }