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

Preserve parent tiles in the source cache #4311

Merged
merged 1 commit into from
Feb 21, 2017
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/source/source_cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ class SourceCache extends Evented {
}
if (this._cache.has(coord.id)) {
retain[coord.id] = true;
return this._cache.get(coord.id);
return this._cache.getWithoutRemoving(coord.id);
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions src/util/lru_cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,21 @@ class LRUCache<T> {
return data;
}

/**
* Get the value attached to a specific key without removing data
* from the cache. If the key is not found, returns `null`
*
* @param {string} key the key to look up
* @returns {*} the data, or null if it isn't found
* @private
*/
getWithoutRemoving(key: string): ?T {
if (!this.has(key)) { return null; }

const data = this.data[key];
return data;
}

/**
* Remove a key/value combination from the cache.
*
Expand Down
2 changes: 1 addition & 1 deletion test/unit/source/source_cache.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ test('SourceCache#findLoadedParent', (t) => {
t.equal(sourceCache.findLoadedParent(new TileCoord(2, 3, 3), 0, retain), undefined);
t.equal(sourceCache.findLoadedParent(new TileCoord(2, 0, 0), 0, retain), tile);
t.deepEqual(retain, expectedRetain);
t.equal(sourceCache._cache.order.length, 0);
t.equal(sourceCache._cache.order.length, 1);

t.end();
});
Expand Down
10 changes: 10 additions & 0 deletions test/unit/util/lru_cache.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ test('LRUCache', (t) => {
t.end();
});

test('LRUCache - getWithoutRemoving', (t) => {
const cache = new LRUCache(10, () => {
t.fail();
});
t.equal(cache.add('washington', 'dc'), cache, '.add()');
t.equal(cache.getWithoutRemoving('washington'), 'dc', '.getWithoutRemoving()');
t.deepEqual(cache.keys(), ['washington'], '.keys()');
t.end();
});

test('LRUCache - duplicate add', (t) => {
const cache = new LRUCache(10, () => {
t.fail();
Expand Down