More cleanup for the tiled layer cache.
This commit is contained in:
parent
a6f10b9ee0
commit
04d2aa1ac1
|
@ -49,7 +49,6 @@ export interface TileSetProperties {
|
||||||
* Idea stolen [on the web](https://dev.to/tiagof/react-re-mounting-vs-re-rendering-lnh)
|
* Idea stolen [on the web](https://dev.to/tiagof/react-re-mounting-vs-re-rendering-lnh)
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
export const TileSet: react.FC<TileSetProperties> = memo(
|
export const TileSet: react.FC<TileSetProperties> = memo(
|
||||||
(props: TileSetProperties) => {
|
(props: TileSetProperties) => {
|
||||||
|
@ -96,14 +95,21 @@ export const TileSet: react.FC<TileSetProperties> = memo(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
if (tiles.size > tileSetConfig.cacheSize) {
|
if (tiles.size > tileSetConfig.cacheSizePerLayer) {
|
||||||
const oldestTileKeys = [...tiles.keys()];
|
const oldestTileKeys = [...tiles.keys()];
|
||||||
oldestTileKeys.splice(-tileSetConfig.cacheSize);
|
oldestTileKeys.splice(-tileSetConfig.cacheSizePerLayer);
|
||||||
oldestTileKeys.forEach((tileKey) => {
|
oldestTileKeys.forEach((tileKey) => {
|
||||||
tiles.delete(tileKey);
|
tiles.delete(tileKey);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
globalThis.cacheForTileSet.set(key, tiles);
|
globalThis.cacheForTileSet.set(key, tiles);
|
||||||
|
if (globalThis.cacheForTileSet > tileSetConfig.numberOfCachedLayers) {
|
||||||
|
const oldestCachedLayerKeys = [...globalThis.cacheForTileSet.keys()];
|
||||||
|
oldestCachedLayerKeys.slice(-tileSetConfig.numberOfCachedLayers);
|
||||||
|
oldestCachedLayerKeys.forEach((cachedLayerKey) => {
|
||||||
|
globalThis.cacheForTileSet.delete(cachedLayerKey);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return <>{Array.from(tiles.values())}</>;
|
return <>{Array.from(tiles.values())}</>;
|
||||||
|
|
|
@ -11,5 +11,6 @@ export const handlersConfig = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const tileSetConfig = {
|
export const tileSetConfig = {
|
||||||
cacheSize: 1000,
|
cacheSizePerLayer: 1000,
|
||||||
}
|
numberOfCachedLayers: 20,
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue