Merge pull request #7842 from ahocevar/labelcache-adjust-size
Allow setting the label cache size
This commit is contained in:
@@ -93,7 +93,10 @@ export const defaultLineWidth = 1;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The label cache for text rendering. To change the default cache size of 2048
|
||||||
|
* entries, use {@link ol.structs.LRUCache#setSize}.
|
||||||
* @type {ol.structs.LRUCache.<HTMLCanvasElement>}
|
* @type {ol.structs.LRUCache.<HTMLCanvasElement>}
|
||||||
|
* @api
|
||||||
*/
|
*/
|
||||||
export const labelCache = new LRUCache();
|
export const labelCache = new LRUCache();
|
||||||
|
|
||||||
|
|||||||
@@ -267,6 +267,16 @@ LRUCache.prototype.set = function(key, value) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a maximum number of entries for the cache.
|
||||||
|
* @param {number} size Cache size.
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
LRUCache.prototype.setSize = function(size) {
|
||||||
|
this.highWaterMark = size;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prune the cache.
|
* Prune the cache.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -280,4 +280,14 @@ describe('ol.structs.LRUCache', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('setting the cache size', function() {
|
||||||
|
it('sets the cache size', function() {
|
||||||
|
lruCache.setSize(2);
|
||||||
|
expect(lruCache.highWaterMark).to.be(2);
|
||||||
|
fillLRUCache(lruCache);
|
||||||
|
lruCache.prune();
|
||||||
|
expect(lruCache.getKeys().length).to.be(2);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user