From 4da41f7fa5fab902b789e1a7bcac966f03f5d69d Mon Sep 17 00:00:00 2001 From: Mattia Bertorello Date: Fri, 12 Jul 2019 14:53:03 +0200 Subject: [PATCH] Complete disable cache if the file is not a *_indexes --- .../src/cc/arduino/utils/network/FileDownloader.java | 8 ++------ .../src/cc/arduino/utils/network/FileDownloaderCache.java | 8 +++++++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/arduino-core/src/cc/arduino/utils/network/FileDownloader.java b/arduino-core/src/cc/arduino/utils/network/FileDownloader.java index 6f4bada2a..95138d8ff 100644 --- a/arduino-core/src/cc/arduino/utils/network/FileDownloader.java +++ b/arduino-core/src/cc/arduino/utils/network/FileDownloader.java @@ -164,7 +164,7 @@ public class FileDownloader extends Observable { try { setStatus(Status.CONNECTING); - final Optional fileCachedOpt = FileDownloaderCache.getFileCached(downloadUrl); + final Optional fileCachedOpt = FileDownloaderCache.getFileCached(downloadUrl, allowCache); if (fileCachedOpt.isPresent()) { final FileDownloaderCache.FileCached fileCached = fileCachedOpt.get(); @@ -175,11 +175,7 @@ public class FileDownloader extends Observable { } else { openConnectionAndFillTheFile(noResume); - if (allowCache) { - fileCached.updateCacheFile(outputFile); - } else { - log.info("The file {} was not cached because allow cache is false", downloadUrl); - } + fileCached.updateCacheFile(outputFile); } } else { openConnectionAndFillTheFile(noResume); diff --git a/arduino-core/src/cc/arduino/utils/network/FileDownloaderCache.java b/arduino-core/src/cc/arduino/utils/network/FileDownloaderCache.java index 9c8648708..d55d5f1ef 100644 --- a/arduino-core/src/cc/arduino/utils/network/FileDownloaderCache.java +++ b/arduino-core/src/cc/arduino/utils/network/FileDownloaderCache.java @@ -118,10 +118,16 @@ public class FileDownloaderCache { } static Optional getFileCached(final URL remoteURL) + throws URISyntaxException, NoSuchMethodException, ScriptException, + IOException { + return getFileCached(remoteURL, true); + } + + static Optional getFileCached(final URL remoteURL, boolean enableCache) throws URISyntaxException, NoSuchMethodException, ScriptException, IOException { // Return always and empty file if the cache is not enable - if (!enableCache) { + if (!(enableCache && FileDownloaderCache.enableCache)) { log.info("The cache is not enable."); return Optional.empty(); }