# LRUCache

class in `3d-tiles-renderer/core`

```js
import { LRUCache } from '3d-tiles-renderer/core';
```

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.

## Properties

### .unloadPriorityCallback: UnloadPriorityCallback | null

default `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

default `6000`

Minimum number of items to keep in the cache after eviction.

### .maxSize: number

default `8000`

Maximum number of items before eviction is triggered.

### .minBytesSize: number

default `~322MB`

Minimum total bytes to retain after eviction.

> **Note:** Only works with three.js r166 or higher.

### .maxBytesSize: number

default `~430MB`

Maximum total bytes before eviction is triggered.

> **Note:** Only works with three.js r166 or higher.

### .unloadPercent: number

default `0.05`

Fraction of excess items/bytes to unload per eviction pass.

### .autoMarkUnused: boolean

default `true`

If true, items are automatically marked as unused at the start of each eviction pass.

### .cachedBytes: number

readonly

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

```js
.isFull(  ): boolean
```

Returns whether the cache has reached its maximum item count or byte size.

### .getMemoryUsage

```js
.getMemoryUsage( item: any ): number
```

Returns the byte size registered for the given item, or 0 if not tracked.

- `item`, `any`

### .setMemoryUsage

```js
.setMemoryUsage( item: any, bytes: number )
```

Sets the byte size for the given item, updating the total `cachedBytes` count.

- `item`, `any`
- `bytes`, `number`

### .add

```js
.add( item: any, removeCb: RemoveCallback ): boolean
```

Adds an item to the cache. Returns false if the item already exists or the cache is full.

- `item`, `any`
- `removeCb`, `RemoveCallback`: Called with the item when it is evicted

### .has

```js
.has( item: any ): boolean
```

Returns whether the given item is in the cache.

- `item`, `any`

### .remove

```js
.remove( item: any ): boolean
```

Removes an item from the cache immediately, invoking its removal callback.
Returns false if the item was not in the cache.

- `item`, `any`

### .setLoaded

```js
.setLoaded( item: any, value: boolean )
```

Marks 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.

- `item`, `any`
- `value`, `boolean`

### .markUsed

```js
.markUsed( item: any )
```

Marks an item as used in the current frame, preventing it from being evicted.

- `item`, `any`

### .markUnused

```js
.markUnused( item: any )
```

Marks an item as unused, making it eligible for eviction.

- `item`, `any`

### .markAllUnused

```js
.markAllUnused(  )
```

Marks all items in the cache as unused.

### .isUsed

```js
.isUsed( item: any ): boolean
```

Returns whether the given item is currently marked as used.

- `item`, `any`

### .unloadUnusedContent

```js
.unloadUnusedContent(  )
```

Evicts unused items until the cache is within its min size and byte limits.
Items are sorted by `unloadPriorityCallback` before eviction.

### .scheduleUnload

```js
.scheduleUnload(  )
```

Schedules `unloadUnusedContent` to run asynchronously via microtask.
