[core] Set priorData from cache only if resource is useable
In cases when cached resource is useable, yet don't have an expiration timestamp, we provided data to the requester from the cache and the same data was returned once 304 response was received from the network.
This commit is contained in:
@@ -81,13 +81,17 @@ public:
|
||||
callback(response);
|
||||
// Set the priority of existing resource to low if it's expired but usable.
|
||||
res.setPriority(Resource::Priority::Low);
|
||||
} else {
|
||||
// Set prior data only if it was not returned to the requester.
|
||||
// Once we get 304 response from the network, we will forward response
|
||||
// to the requester.
|
||||
res.priorData = response.data;
|
||||
}
|
||||
|
||||
// Copy response fields for cache control request
|
||||
res.priorModified = response.modified;
|
||||
res.priorExpires = response.expires;
|
||||
res.priorEtag = response.etag;
|
||||
res.priorData = response.data;
|
||||
}
|
||||
|
||||
tasks[req] = requestFromNetwork(res, std::move(tasks[req]));
|
||||
|
||||
@@ -60,7 +60,8 @@ void SpriteLoader::load(const std::string& url, FileSource& fileSource) {
|
||||
emitSpriteLoadedIfComplete();
|
||||
} else {
|
||||
// Only trigger a sprite loaded event we got new data.
|
||||
loader->json = res.data;
|
||||
assert(loader->json != res.data);
|
||||
loader->json = std::move(res.data);
|
||||
emitSpriteLoadedIfComplete();
|
||||
}
|
||||
});
|
||||
@@ -74,7 +75,8 @@ void SpriteLoader::load(const std::string& url, FileSource& fileSource) {
|
||||
loader->image = std::make_shared<std::string>();
|
||||
emitSpriteLoadedIfComplete();
|
||||
} else {
|
||||
loader->image = res.data;
|
||||
assert(loader->image != res.data);
|
||||
loader->image = std::move(res.data);
|
||||
emitSpriteLoadedIfComplete();
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user