Cache asset indexes by ETag cache

This commit is contained in:
huanghongxun 2018-10-09 20:22:54 +08:00
parent 5323aaed6d
commit 07a701e572
2 changed files with 4 additions and 10 deletions

View File

@ -58,7 +58,7 @@ public final class GameAssetIndexDownloadTask extends Task {
}
@Override
public void execute() throws Exception {
public void execute() {
AssetIndexInfo assetIndexInfo = version.getAssetIndex();
File assetIndexFile = dependencyManager.getGameRepository().getIndexFile(version.getId(), assetIndexInfo.getId());
@ -67,10 +67,7 @@ public final class GameAssetIndexDownloadTask extends Task {
dependencies.add(new FileDownloadTask(
NetworkUtils.toURL(dependencyManager.getDownloadProvider().injectURL(assetIndexInfo.getUrl())),
assetIndexFile
).setCaching(true)
.setCacheRepository(dependencyManager.getCacheRepository())
.setCandidate(dependencyManager.getCacheRepository().getCommonDirectory()
.resolve("assets").resolve("indexes").resolve(assetIndexInfo.getId() + ".json")));
).setCacheRepository(dependencyManager.getCacheRepository()));
}
}

View File

@ -299,12 +299,9 @@ public class FileDownloadTask extends Task {
integrityCheck.performCheck(digest);
}
if (caching) {
if (caching && integrityCheck != null) {
try {
if (integrityCheck == null)
repository.cacheFile(file.toPath(), CacheRepository.SHA1, Hex.encodeHex(DigestUtils.digest(CacheRepository.SHA1, file.toPath())));
else
repository.cacheFile(file.toPath(), integrityCheck.getAlgorithm(), integrityCheck.getChecksum());
repository.cacheFile(file.toPath(), integrityCheck.getAlgorithm(), integrityCheck.getChecksum());
} catch (IOException e) {
Logging.LOG.log(Level.WARNING, "Failed to cache file", e);
}