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>
This commit is contained in:
flow
2022-07-17 11:24:12 -03:00
parent c8a72c876d
commit ab6e1b112b
3 changed files with 53 additions and 9 deletions

View File

@ -64,6 +64,14 @@ class MetaEntry {
auto getMD5Sum() -> QString { return md5sum; }
void setMD5Sum(QString md5sum) { this->md5sum = md5sum; }
auto getCurrentAge() -> qint64 { return current_age; }
void setCurrentAge(qint64 age) { current_age = age; }
auto getMaximumAge() -> qint64 { return max_age; }
void setMaximumAge(qint64 age) { max_age = age; }
bool isExpired(qint64 offset) { return current_age >= max_age - offset; };
protected:
QString baseId;
QString basePath;
@ -72,6 +80,8 @@ class MetaEntry {
QString etag;
qint64 local_changed_timestamp = 0;
QString remote_changed_timestamp; // QString for now, RFC 2822 encoded time
qint64 current_age = 0;
qint64 max_age = 0;
bool stale = true;
};