diff options
author | flow <flowlnlnln@gmail.com> | 2022-07-16 20:29:03 -0300 |
---|---|---|
committer | flow <flowlnlnln@gmail.com> | 2022-07-16 21:25:28 -0300 |
commit | ec87a8ddfc2e6c23ab4c1003f6cafa685ce233d8 (patch) | |
tree | c895b8dd7d198f972e269531f55c564dd16eef53 /launcher | |
parent | dce435c882b3370d04ff9c0af9e690a703007628 (diff) | |
download | PrismLauncher-ec87a8ddfc2e6c23ab4c1003f6cafa685ce233d8.tar.gz PrismLauncher-ec87a8ddfc2e6c23ab4c1003f6cafa685ce233d8.tar.bz2 PrismLauncher-ec87a8ddfc2e6c23ab4c1003f6cafa685ce233d8.zip |
fix: add expiration time to cache entries
This is to prevent problems where the cache entry would still be used
way after the remote resource got updated. The limit is hardcoded for 1
week, which I think is a reasonable time, but this could be further
tweaked.
Signed-off-by: flow <flowlnlnln@gmail.com>
Diffstat (limited to 'launcher')
-rw-r--r-- | launcher/net/HttpMetaCache.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/launcher/net/HttpMetaCache.cpp b/launcher/net/HttpMetaCache.cpp index 4d86c0b8..769f162b 100644 --- a/launcher/net/HttpMetaCache.cpp +++ b/launcher/net/HttpMetaCache.cpp @@ -44,6 +44,11 @@ #include <QDebug> +/** 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"); |