Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] Set priorData from cache only if resource is useable
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alexshalamov committed Feb 14, 2020
1 parent 06f7951 commit 89eab05
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 5 additions & 1 deletion platform/default/src/mbgl/storage/main_resource_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,17 @@ class MainResourceLoaderThread {
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]));
Expand Down
6 changes: 4 additions & 2 deletions src/mbgl/sprite/sprite_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
Expand All @@ -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();
}
});
Expand Down

0 comments on commit 89eab05

Please sign in to comment.