diff --git a/launcher/net/HttpMetaCache.cpp b/launcher/net/HttpMetaCache.cpp index 4d86c0b84..769f162b8 100644 --- a/launcher/net/HttpMetaCache.cpp +++ b/launcher/net/HttpMetaCache.cpp @@ -44,6 +44,11 @@ #include +/** Maximum time to hold a cache entry + * = 1 week in milliseconds + */ +#define TIME_TO_EXPIRE 1*7*24*60*60*1000 + auto MetaEntry::getFullPath() -> QString { // FIXME: make local? @@ -121,6 +126,15 @@ auto HttpMetaCache::resolveEntry(QString base, QString resource_path, QString ex SaveEventually(); } + // Get rid of old entries, to prevent cache problems + auto current_time = QDateTime::currentMSecsSinceEpoch(); + auto remote_time = QDateTime::fromString(entry->remote_changed_timestamp).toMSecsSinceEpoch(); + if (current_time - remote_time < TIME_TO_EXPIRE) { + 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; @@ -240,6 +254,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");