Only schedule the icon cache expire when it's needed
This commit is contained in:
@@ -54,7 +54,7 @@ import {create as createTransform, apply as applyTransform} from './transform.js
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {function(PluggableMap, ?FrameState): boolean} PostRenderFunction
|
* @typedef {function(PluggableMap, ?FrameState): any} PostRenderFunction
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -280,7 +280,9 @@ class MapRenderer extends Disposable {
|
|||||||
* @protected
|
* @protected
|
||||||
*/
|
*/
|
||||||
scheduleExpireIconCache(frameState) {
|
scheduleExpireIconCache(frameState) {
|
||||||
frameState.postRenderFunctions.push(/** @type {import("../PluggableMap.js").PostRenderFunction} */ (expireIconCache));
|
if (iconImageCache.canExpireCache()) {
|
||||||
|
frameState.postRenderFunctions.push(expireIconCache);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -37,11 +37,18 @@ class IconImageCache {
|
|||||||
this.cacheSize_ = 0;
|
this.cacheSize_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {boolean} Can expire cache.
|
||||||
|
*/
|
||||||
|
canExpireCache() {
|
||||||
|
return this.cacheSize_ > this.maxCacheSize_;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FIXME empty description for jsdoc
|
* FIXME empty description for jsdoc
|
||||||
*/
|
*/
|
||||||
expire() {
|
expire() {
|
||||||
if (this.cacheSize_ > this.maxCacheSize_) {
|
if (this.canExpireCache()) {
|
||||||
let i = 0;
|
let i = 0;
|
||||||
for (const key in this.cache_) {
|
for (const key in this.cache_) {
|
||||||
const iconImage = this.cache_[key];
|
const iconImage = this.cache_[key];
|
||||||
|
|||||||
Reference in New Issue
Block a user