[core] only cache successful or NotFound responses

We don't want other types of error end up in our cache, since it'll likely evict perfectly good content.
This commit is contained in:
Konstantin Käfer
2016-01-07 11:40:43 +01:00
parent c5feadf0bd
commit a06f28ddb7
3 changed files with 182 additions and 1 deletions

View File

@@ -276,7 +276,12 @@ void OnlineFileSource::Impl::startRealRequest(OnlineFileRequestImpl& request) {
auto callback = [this, &request](std::shared_ptr<const Response> response) {
request.realRequest = nullptr;
if (cache && !util::isAssetURL(request.resource.url)) {
// Only update the cache for successful or 404 responses.
// In particular, we don't want to write a Canceled request, or one that failed due to
// connection errors to the cache. Server errors are hopefully also temporary, so we're not
// caching them either.
if (cache && !util::isAssetURL(request.resource.url) &&
(!response->error || (response->error->reason == Response::Error::Reason::NotFound))) {
// Store response in database. Make sure we only refresh the expires column if the data
// didn't change.
FileCache::Hint hint = FileCache::Hint::Full;