Experiment with new CachedResource framework
This commit is contained in:
parent
95ce706e2e
commit
e9f92a87e6
|
@ -15,7 +15,7 @@ import net.filebot.web.WebRequest;
|
|||
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
public class CachedResource2<K, R> implements Resource<R> {
|
||||
public class CachedResource2<K, R> {
|
||||
|
||||
public static final int DEFAULT_RETRY_LIMIT = 2;
|
||||
public static final Duration DEFAULT_RETRY_DELAY = Duration.ofSeconds(2);
|
||||
|
@ -50,7 +50,6 @@ public class CachedResource2<K, R> implements Resource<R> {
|
|||
this.cache = cache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized R get() throws Exception {
|
||||
Object value = cache.computeIfStale(key, expirationTime, element -> {
|
||||
URL resource = source.source(key);
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
package net.filebot;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Resource<R> {
|
||||
|
||||
R get() throws Exception;
|
||||
|
||||
}
|
|
@ -15,7 +15,6 @@ import javax.swing.Icon;
|
|||
|
||||
import net.filebot.Cache;
|
||||
import net.filebot.CacheType;
|
||||
import net.filebot.Resource;
|
||||
import net.filebot.ResourceManager;
|
||||
|
||||
public class TVMazeClient extends AbstractEpisodeListProvider {
|
||||
|
@ -113,8 +112,7 @@ public class TVMazeClient extends AbstractEpisodeListProvider {
|
|||
|
||||
protected Object request(String resource) throws Exception {
|
||||
Cache cache = Cache.getCache(getName(), CacheType.Monthly);
|
||||
Resource<Object> json = cache.json(resource, s -> getResource(resource), Cache.ONE_DAY);
|
||||
return json.get();
|
||||
return cache.json(resource, s -> getResource(resource), Cache.ONE_DAY).get();
|
||||
}
|
||||
|
||||
protected URL getResource(String resource) throws Exception {
|
||||
|
|
|
@ -28,7 +28,6 @@ import javax.swing.Icon;
|
|||
|
||||
import net.filebot.Cache;
|
||||
import net.filebot.CacheType;
|
||||
import net.filebot.Resource;
|
||||
import net.filebot.ResourceManager;
|
||||
import net.filebot.util.FileUtilities;
|
||||
import net.filebot.web.TheTVDBClient.BannerDescriptor.BannerProperty;
|
||||
|
@ -301,8 +300,7 @@ public class TheTVDBClient extends AbstractEpisodeListProvider {
|
|||
|
||||
protected Document getXmlResource(MirrorType mirror, String resource) throws Exception {
|
||||
Cache cache = Cache.getCache(getName(), CacheType.Monthly);
|
||||
Resource<Document> xml = cache.xml(resource, s -> getResource(mirror, s), Cache.ONE_DAY);
|
||||
return xml.get();
|
||||
return cache.xml(resource, s -> getResource(mirror, s), Cache.ONE_DAY).get();
|
||||
}
|
||||
|
||||
protected URL getResource(MirrorType mirror, String path) throws Exception {
|
||||
|
|
Loading…
Reference in New Issue