---
url: https://docs.moqtail.dev/ts/api/client/interfaces/ObjectCache.md
---
# Interface: ObjectCache

In‑memory index of [MoqtObject](../../model/classes/MoqtObject.md) instances keyed by their [Location](../../model/classes/Location.md) (group/subgroup/object),
providing ordered insertion and range queries.

Implementations MUST keep objects sorted ascending by (groupId, objectId) so binary searches can
locate insertion points / range bounds efficiently. Subgroup ordinality is currently ignored for ordering
(adjust if protocol semantics require finer granularity later).

## Example

**Typical usage**

```ts
const cache: ObjectCache = new MemoryObjectCache()
cache.add(obj)
const window = cache.getRange(startLoc, endLoc)
const exact = cache.getByLocation(loc)
```

Concurrency: Implementations here are not thread‑safe; callers avoid concurrent mutation from workers.

## Methods

### add()

> **add**(`obj`): `void`

Insert a new [MoqtObject](../../model/classes/MoqtObject.md), preserving sorted order (duplicates allowed or replaced impl‑defined).

#### Parameters

##### obj

[`MoqtObject`](../../model/classes/MoqtObject.md)

#### Returns

`void`

***

### clear()

> **clear**(): `void`

Remove all cached objects.

#### Returns

`void`

***

### getByLocation()

> **getByLocation**(`location`): [`MoqtObject`](../../model/classes/MoqtObject.md) | `undefined`

Return the object whose Location exactly matches (group & object) or undefined if absent.

#### Parameters

##### location

[`Location`](../../model/classes/Location.md)

#### Returns

[`MoqtObject`](../../model/classes/MoqtObject.md) | `undefined`

***

### getRange()

> **getRange**(`start?`, `end?`): [`MoqtObject`](../../model/classes/MoqtObject.md)\[]

Return a shallow copy array of objects whose Location is >= start and < end (end exclusive).

#### Parameters

##### start?

[`Location`](../../model/classes/Location.md)

##### end?

[`Location`](../../model/classes/Location.md)

#### Returns

[`MoqtObject`](../../model/classes/MoqtObject.md)\[]

***

### size()

> **size**(): `number`

Current number of cached objects.

#### Returns

`number`
