diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/CacheRepository.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/CacheRepository.java index 77843bbd99..d5b18c60fa 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/CacheRepository.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/CacheRepository.java @@ -231,7 +231,7 @@ public synchronized void cacheData(ExceptionalSupplier String url = conn.getURL().toString(); String lastModified = conn.getHeaderField("Last-Modified"); CacheResult cacheResult = cacheSupplier.get(); - ETagItem eTagItem = new ETagItem(url, eTag, cacheResult.hash, Files.getLastModifiedTime(cacheResult.cachedFile).toMillis(), lastModified); + ETagItem eTagItem = new ETagItem(url, eTag, cacheResult.hash, Files.getLastModifiedTime(cacheResult.cachedFile).toMillis(), lastModified, 0L); Lock writeLock = lock.writeLock(); writeLock.lock(); try { @@ -325,19 +325,24 @@ private static final class ETagItem { @SerializedName("remote") private final String remoteLastModified; + // The `expires` field is not used in HMCL 3.6.x, but will be used in HMCL 3.7.x. + // We backported this field to 3.6.x to avoid breaking the etag.json file created by newer HMCL versions. + private final long expires; + /** * For Gson. */ public ETagItem() { - this(null, null, null, 0, null); + this(null, null, null, 0, null, 0L); } - public ETagItem(String url, String eTag, String hash, long localLastModified, String remoteLastModified) { + public ETagItem(String url, String eTag, String hash, long localLastModified, String remoteLastModified, long expires) { this.url = url; this.eTag = eTag; this.hash = hash; this.localLastModified = localLastModified; this.remoteLastModified = remoteLastModified; + this.expires = expires; } public int compareTo(ETagItem other) { @@ -361,12 +366,13 @@ public boolean equals(Object o) { Objects.equals(url, eTagItem.url) && Objects.equals(eTag, eTagItem.eTag) && Objects.equals(hash, eTagItem.hash) && - Objects.equals(remoteLastModified, eTagItem.remoteLastModified); + Objects.equals(remoteLastModified, eTagItem.remoteLastModified) && + expires == eTagItem.expires; } @Override public int hashCode() { - return Objects.hash(url, eTag, hash, localLastModified, remoteLastModified); + return Objects.hash(url, eTag, hash, localLastModified, remoteLastModified, expires); } }