aboutsummaryrefslogtreecommitdiff
path: root/launcher/net/HttpMetaCache.cpp
diff options
context:
space:
mode:
authorflow <flowlnlnln@gmail.com>2022-07-17 11:24:12 -0300
committerflow <flowlnlnln@gmail.com>2022-07-21 19:19:24 -0300
commitab6e1b112b05a1fcad962d15c087ed9ae746bf87 (patch)
treec27b407805e58c99f774b94a7c5a431986657098 /launcher/net/HttpMetaCache.cpp
parentc8a72c876da69de669d5616dd7ff755f157baf99 (diff)
downloadPrismLauncher-ab6e1b112b05a1fcad962d15c087ed9ae746bf87.tar.gz
PrismLauncher-ab6e1b112b05a1fcad962d15c087ed9ae746bf87.tar.bz2
PrismLauncher-ab6e1b112b05a1fcad962d15c087ed9ae746bf87.zip
change(cache): use cache-specific http headers for their lifetime
This uses the 'Age', 'Cache-Control' and 'Expires' HTTP headers to more accurately set up the cache lifetime, falling back to a static 1-week time if they're not present in the response. Signed-off-by: flow <flowlnlnln@gmail.com>
Diffstat (limited to 'launcher/net/HttpMetaCache.cpp')
-rw-r--r--launcher/net/HttpMetaCache.cpp14
1 files changed, 6 insertions, 8 deletions
diff --git a/launcher/net/HttpMetaCache.cpp b/launcher/net/HttpMetaCache.cpp
index 769f162b..deb2780b 100644
--- a/launcher/net/HttpMetaCache.cpp
+++ b/launcher/net/HttpMetaCache.cpp
@@ -44,11 +44,6 @@
#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?
@@ -127,9 +122,8 @@ auto HttpMetaCache::resolveEntry(QString base, QString resource_path, QString ex
}
// 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) {
+ 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);
@@ -235,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;
@@ -275,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);
}
}