Skip to content

Commit

Permalink
manually strip urls for faster cache matching (#8434) (#8449)
Browse files Browse the repository at this point in the history
  • Loading branch information
mourner authored Jul 9, 2019
1 parent bc9efe4 commit 9235d6a
Showing 1 changed file with 5 additions and 2 deletions.
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

0 comments on commit 9235d6a

Please sign in to comment.