diff --git a/org.eclipse.lsp4xml/pom.xml b/org.eclipse.lsp4xml/pom.xml
index 410c2b931f..9c8c138647 100644
--- a/org.eclipse.lsp4xml/pom.xml
+++ b/org.eclipse.lsp4xml/pom.xml
@@ -103,5 +103,10 @@
junit
test
+
+ com.github.ben-manes.caffeine
+ caffeine
+ 2.5.5
+
\ No newline at end of file
diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/uriresolver/CacheResourcesManager.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/uriresolver/CacheResourcesManager.java
index bfa541e9e0..ce94038a5f 100644
--- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/uriresolver/CacheResourcesManager.java
+++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/uriresolver/CacheResourcesManager.java
@@ -27,9 +27,13 @@
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+
import org.eclipse.lsp4xml.utils.FilesUtils;
import org.eclipse.lsp4xml.utils.URIUtils;
@@ -38,6 +42,10 @@
*
*/
public class CacheResourcesManager {
+ private final Cache unavailableURICache = Caffeine.newBuilder()
+ .expireAfterWrite(1, TimeUnit.MINUTES)
+ .maximumSize(100)
+ .build();
private static final String CACHE_PATH = "cache";
private static final Logger LOGGER = Logger.getLogger(CacheResourcesManager.class.getName());
@@ -83,10 +91,16 @@ public CacheResourcesManager() {
}
public Path getResource(final String resourceURI) throws IOException {
+ LOGGER.info("DELETE THIS !@#");
Path resourceCachePath = getResourceCachePath(resourceURI);
if (Files.exists(resourceCachePath)) {
return resourceCachePath;
}
+
+ if(unavailableURICache.getIfPresent(resourceURI) != null) {
+ return null;
+ }
+
CompletableFuture f = null;
synchronized (resourcesLoading) {
if (resourcesLoading.containsKey(resourceURI)) {
@@ -139,11 +153,12 @@ private CompletableFuture downloadResource(final String resourceURI, Path
LOGGER.info("Downloaded " + resourceURI + " to " + resourceCachePath + " in " + elapsed + "ms");
} catch (Exception e) {
// Do nothing
+ unavailableURICache.put(resourceURI, true);
Throwable rootCause = getRootCause(e);
String error = "[" + rootCause.getClass().getTypeName() + "] " + rootCause.getMessage();
LOGGER.log(Level.SEVERE,
"Error while downloading " + resourceURI + " to " + resourceCachePath + " : " + error);
- throw new CacheResourceDownloadedException("Error while downloading '" + resourceURI + "'.", e);
+ throw new CacheResourceDownloadedException("Error while downloading '" + resourceURI + "' to " + resourceCachePath + ".", e);
} finally {
synchronized (resourcesLoading) {
resourcesLoading.remove(resourceURI);
diff --git a/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/uriresolver/CacheResourcesManagerTest.java b/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/uriresolver/CacheResourcesManagerTest.java
index 28437b4e15..11bc52f350 100644
--- a/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/uriresolver/CacheResourcesManagerTest.java
+++ b/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/uriresolver/CacheResourcesManagerTest.java
@@ -12,6 +12,9 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+
+import java.io.IOException;
import org.junit.Test;
@@ -32,4 +35,9 @@ private void testCanUseCache(boolean useCacheEnabled) {
assertFalse(cacheResourcesManager.canUseCache("file:///foo"));
}
+ @Test
+ public void testUnavailableCache() {
+
+ }
+
}
\ No newline at end of file