1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-21 23:38:50 -05:00

Initialize etag cache on demand

This commit is contained in:
Reinhard Pointner 2019-06-10 21:02:07 +07:00
parent e5ecc6a04f
commit ff422c39fa

View File

@ -221,18 +221,18 @@ public class CachedResource<K, R> implements Resource<R> {
public static Fetch fetchIfNoneMatch(Transform<URL, ?> key, Cache cache) { public static Fetch fetchIfNoneMatch(Transform<URL, ?> key, Cache cache) {
// create cache with the same config // create cache with the same config
Cache etagStorage = Cache.getCache(cache.getName() + "_etag", cache.getCacheType()); Resource<Cache> etagStorage = Resource.lazy(() -> Cache.getCache(cache.getName() + "_etag", cache.getCacheType()));
// make sure value cache contains key, otherwise ignore previously stored etag // make sure value cache contains key, otherwise ignore previously stored etag
return fetchIfNoneMatch(url -> { return fetchIfNoneMatch(url -> {
try { 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) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
}, (url, etag) -> { }, (url, etag) -> {
try { try {
etagStorage.put(key.transform(url), etag); etagStorage.get().put(key.transform(url), etag);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }