diff options
author | timoreo <contact@timoreo.fr> | 2022-08-11 07:32:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-11 07:32:43 +0200 |
commit | 1a5986abe0d9c8e483eaa5f8ee5e8c306478370f (patch) | |
tree | 18cef990e061a003647edb1171db1e60cf8db4a6 /launcher/net/HttpMetaCache.cpp | |
parent | a5da3db9662a94b601bb203ce75084be522cfa91 (diff) | |
parent | ab6e1b112b05a1fcad962d15c087ed9ae746bf87 (diff) | |
download | PrismLauncher-1a5986abe0d9c8e483eaa5f8ee5e8c306478370f.tar.gz PrismLauncher-1a5986abe0d9c8e483eaa5f8ee5e8c306478370f.tar.bz2 PrismLauncher-1a5986abe0d9c8e483eaa5f8ee5e8c306478370f.zip |
Merge pull request #920 from flowln/metacache_fix
Diffstat (limited to 'launcher/net/HttpMetaCache.cpp')
-rw-r--r-- | launcher/net/HttpMetaCache.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/launcher/net/HttpMetaCache.cpp b/launcher/net/HttpMetaCache.cpp index 4d86c0b8..deb2780b 100644 --- a/launcher/net/HttpMetaCache.cpp +++ b/launcher/net/HttpMetaCache.cpp @@ -121,6 +121,14 @@ auto HttpMetaCache::resolveEntry(QString base, QString resource_path, QString ex SaveEventually(); } + // Get rid of old entries, to prevent cache problems + auto current_time = QDateTime::currentSecsSinceEpoch(); + if (entry->isExpired(current_time - ( file_last_changed / 1000 ))) { + qWarning() << "Removing cache entry because of old age!"; + selected_base.entry_list.remove(resource_path); + return staleEntry(base, resource_path); + } + // entry passed all the checks we cared about. entry->basePath = getBasePath(base); return entry; @@ -221,6 +229,8 @@ void HttpMetaCache::Load() foo->etag = Json::ensureString(element_obj, "etag"); foo->local_changed_timestamp = Json::ensureDouble(element_obj, "last_changed_timestamp"); foo->remote_changed_timestamp = Json::ensureString(element_obj, "remote_changed_timestamp"); + foo->current_age = Json::ensureDouble(element_obj, "current_age"); + foo->max_age = Json::ensureDouble(element_obj, "max_age"); // presumed innocent until closer examination foo->stale = false; @@ -240,6 +250,8 @@ void HttpMetaCache::SaveNow() if (m_index_file.isNull()) return; + qDebug() << "[HttpMetaCache]" << "Saving metacache with" << m_entries.size() << "entries"; + QJsonObject toplevel; Json::writeString(toplevel, "version", "1"); @@ -259,6 +271,8 @@ void HttpMetaCache::SaveNow() entryObj.insert("last_changed_timestamp", QJsonValue(double(entry->local_changed_timestamp))); if (!entry->remote_changed_timestamp.isEmpty()) entryObj.insert("remote_changed_timestamp", QJsonValue(entry->remote_changed_timestamp)); + entryObj.insert("current_age", QJsonValue(double(entry->current_age))); + entryObj.insert("max_age", QJsonValue(double(entry->max_age))); entriesArr.append(entryObj); } } |