Least-recently-used cache for managing tile content lifecycle. Tracks which items are in use each frame and evicts unused items when the cache exceeds its size limits.
On this page
Properties
unloadPriorityCallback: ( a: any, b: any ) => number | null = null
Comparator used to determine eviction order. Items that sort last are evicted first.
When null, eviction order is by last-used time.
minSize: number = 6000
Minimum number of items to keep in the cache after eviction.
maxSize: number = 8000
Maximum number of items before eviction is triggered.
minBytesSize: number = ~322MB
Minimum total bytes to retain after eviction.
maxBytesSize: number = ~430MB
Maximum total bytes before eviction is triggered.
unloadPercent: number = 0.05
Fraction of excess items/bytes to unload per eviction pass.
autoMarkUnused: boolean = true
If true, items are automatically marked as unused at the start of each eviction pass.
Total number of bytes tracked for the items currently in the cache. Can be used
alongside maxBytesSize and isFull to adjust settings as memory grows.
Methods
isFull(): booleanReturns whether the cache has reached its maximum item count or byte size.
getMemoryUsage( item: any ): numberReturns the byte size registered for the given item, or 0 if not tracked.
setMemoryUsage( item: any, bytes: number ): voidSets the byte size for the given item, updating the total cachedBytes count.
add(
item: any,
// Called with the item when it is evicted
removeCb: ( item: any ) => void
): booleanAdds an item to the cache. Returns false if the item already exists or the cache is full.
has( item: any ): booleanReturns whether the given item is in the cache.
remove( item: any ): booleanRemoves an item from the cache immediately, invoking its removal callback. Returns false if the item was not in the cache.
setLoaded( item: any, value: boolean ): voidMarks whether an item has finished loading. Unloaded items may be evicted early when the cache is over its max size limits, even if they are marked as used.
markUsed( item: any ): voidMarks an item as used in the current frame, preventing it from being evicted.
markUnused( item: any ): voidMarks an item as unused, making it eligible for eviction.
markAllUnused(): voidMarks all items in the cache as unused.
isUsed( item: any ): booleanReturns whether the given item is currently marked as used.
unloadUnusedContent(): voidEvicts unused items until the cache is within its min size and byte limits.
Items are sorted by unloadPriorityCallback before eviction.
scheduleUnload(): voidSchedules unloadUnusedContent to run asynchronously via microtask.