CesiumGS / CesiumGS/cesium-native
Fix calculation of cache expiration time
- Dominant language
- C++
- Stars
- 623
- Forks
- 277
- PR merge metrics
- No merged PRs in 30d
Description
Technically we should subtract the value of the Age header from the max-age, before adding it to the current time. There's a note about this on the Mozilla cache-control page:
> Note that max-age is not the elapsed time since the response was received; it is the elapsed time since the response was generated on the origin server. So if the other cache(s) — on the network route taken by the response — store the response for 100 seconds (indicated using the Age response header field), the browser cache would deduct 100 seconds from its freshness lifetime.
Originally reported by @kring
From `CesiumAsync\src\CachingAssetAccessor.cpp`
```
std::time_t calculateExpiryTime(
const IAssetRequest& request,
const std::optional& cacheControl) {
if (cacheControl) {
if (cacheControl->maxAge() != 0) {
return std::time(nullptr) + cacheControl->maxAge();
}
}
const IAssetResponse* pResponse = request.response();
const HttpHeaders& responseHeaders = pResponse->headers();
HttpHeaders::const_iterator expiresHeader = responseHeaders.find("Expires");
if (expiresHeader != responseHeaders.end()) {
return convertHttpDateToTime(expiresHeader->second);
}
```
Contributor guide
Assessment
This issue has not been assessed yet.