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

Allow 0s for maxCacheSize and maxCacheByteSize #9156

Merged
merged 2 commits into from
Sep 16, 2024
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: 2 additions & 0 deletions docs/api-reference/geo-layers/tile-layer.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ If not supplied, the `maxCacheSize` is calculated as `5` times the number of til

The maximum memory used for caching tiles. If this limit is supplied, `getTileData` must return an object that contains a `byteLength` field.

If not supplied, the `maxCacheByteSize` is set to `Infinity`.

- Default: `null`


Expand Down
10 changes: 5 additions & 5 deletions modules/geo-layers/src/tileset-2d/tileset-2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export class Tileset2D {

this.onTileLoad = tile => {
this.opts.onTileLoad?.(tile);
if (this.opts.maxCacheByteSize) {
if (this.opts.maxCacheByteSize != null) {
this._cacheByteSize += tile.byteLength;
this._resizeCache();
}
Expand Down Expand Up @@ -469,18 +469,18 @@ export class Tileset2D {
const {_cache, opts} = this;

const maxCacheSize =
opts.maxCacheSize ||
opts.maxCacheSize ??
// @ts-expect-error called only when selectedTiles is initialized
(opts.maxCacheByteSize ? Infinity : DEFAULT_CACHE_SCALE * this.selectedTiles.length);
const maxCacheByteSize = opts.maxCacheByteSize || Infinity;
(opts.maxCacheByteSize != null ? Infinity : DEFAULT_CACHE_SCALE * this.selectedTiles.length);
const maxCacheByteSize = opts.maxCacheByteSize ?? Infinity;

const overflown = _cache.size > maxCacheSize || this._cacheByteSize > maxCacheByteSize;

if (overflown) {
for (const [id, tile] of _cache) {
if (!tile.isVisible && !tile.isSelected) {
// delete tile
this._cacheByteSize -= opts.maxCacheByteSize ? tile.byteLength : 0;
this._cacheByteSize -= opts.maxCacheByteSize != null ? tile.byteLength : 0;
_cache.delete(id);
this.opts.onTileUnload?.(tile);
}
Expand Down
Loading