@rbxts/objectcache
v1.0.0
Published
Unofficial roblox-ts port of ObjectCache (high-performance part cache using BulkMoveTo)
Readme
Disclaimer
This is an unofficial port. It is not from the original ObjectCache author and is not endorsed by them. It was ported from the Roblox (Luau) module into TypeScript for use with roblox-ts.
The maintainer of this npm package plans to publish updates when convenient, including after the upstream ObjectCache asset on Creator Store sees meaningful changes.
Introduction
ObjectCache is a modern implementation for handling thousands of active parts while keeping performance high.
Why ObjectCache?
The source logic stays minimal, and it relies on Roblox’s BulkMoveTo API: instead of setting each part’s CFrame one by one, moves are batched. Returned objects are queued and moved in the same frame you call the methods.
Models
With a Model template, set PrimaryPart and weld parts to it. The cache uses BulkMoveTo on the primary part so the whole model moves efficiently.
API
Luau (original module):
local ObjectCache = require(...)
local cache = ObjectCache.new(template, cacheSize, cachesContainer)
cache:GetPart(partCFrame?)
cache:ReturnPart(part)
cache:Update()
cache:ExpandCache(amount)
cache:SetExpandAmount(amount)
cache:IsInUse(object)
cache:Destroy()TypeScript (this package):
import { ObjectCache } from "@rbxts/objectcache-ts";
const cache = new ObjectCache(template, cacheSize, cachesContainer);The roblox-ts compiler emits a Luau class with ObjectCache.new(...), matching the original constructor style on the engine side.
GetPart(partCFrame?: CFrame): TReturnPart(part: BasePart): voidUpdate(): voidExpandCache(amount: number): voidSetExpandAmount(amount: number): voidIsInUse(object: BasePart): booleanDestroy(): voidCacheHolder—Folderholding cached instances
Template may be a BasePart or a Model (with PrimaryPart set). Optional cacheSize defaults to 10; optional cachesContainer defaults to Workspace.
Passing a CFrame into GetPart is optional but can reduce work when used together with ReturnPart, since both queue BulkMoveTo calls.
Installation
npm install @rbxts/objectcache-tsReference implementation (Luau / Creator Store): ObjectCache
License
The upstream ObjectCache project is MIT licensed (Copyright (c) 2024 Pyseph). Treat this port as derived work under compatible terms.
