Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CP] Fix cache match performance #8449

Merged
merged 1 commit into from
Jul 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/util/tile_request_cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,20 @@ function stripQueryParameters(url: string) {
export function cacheGet(request: Request, callback: (error: ?any, response: ?Response, fresh: ?boolean) => void) {
if (!window.caches) return callback(null);

const strippedURL = stripQueryParameters(request.url);

window.caches.open(CACHE_NAME)
.catch(callback)
.then(cache => {
cache.match(request, { ignoreSearch: true })
// manually strip URL instead of `ignoreSearch: true` because of a known
// performance issue in Chrome https://github.com/mapbox/mapbox-gl-js/issues/8431
cache.match(strippedURL)
.catch(callback)
.then(response => {
const fresh = isFresh(response);

// Reinsert into cache so that order of keys in the cache is the order of access.
// This line makes the cache a LRU instead of a FIFO cache.
const strippedURL = stripQueryParameters(request.url);
cache.delete(strippedURL);
if (fresh) {
cache.put(strippedURL, response.clone());
Expand Down