ObjectCache - a modern, blazing-fast model and part cache!

ObjectCache

by Pyseph

Get the module here

Introduction

ObjectCache is a modern implementation on handling thousands of active parts, while keeping performance high.

Why ObjectCache?

The source code is minimal and with no bloat, and has another important difference - it uses Roblox’s BulkMoveTo API to achieve peak performance!
Instead of manually setting the CFrame of each part one-by-one, all parts are batched together into a single movement call. And best of all, you don’t need to worry about any of this! ObjectCache puts all returned objects into a queue to move them away in the same frame as you call the method.

Supports models

By utilizing the engine’s behavior, ObjectCache supports using models directly – and it remains as efficient as ever, much faster than calling :PivotTo! To use a model as the template, you just have to set a PrimaryPart, and weld all parts in the model to the PrimaryPart. ObjectCache will call BulkMoveTo on the PrimaryPart, which will automatically move all the other parts in the model with it, at much faster speeds than normal!

API

The API is dead simple - easy to learn, and eventually forget.

ObjectCache is fully typed, but an API reference is always handy to have:

ObjectCacheConstructor.new(
    Template: BasePart | Model,
    CacheSize: number?,
    CachesContainer: Folder?
) -> ObjectCache

ObjectCache:GetPart(PartCFrame: CFrame?): BasePart

ObjectCache:ReturnPart(Part: BasePart)

Cache:IsInUse(Part: BasePart): boolean

ObjectCache:Update()

Cache:ExpandCache(Amount)

Cache:SetExpandAmount(Amount: number)

ObjectCache:Destroy()

You may have noticed that ObjectCache:GetPart lets you provide an optional target CFrame. This argument lets you squeeze out the maximum performance out of the module! Since :GetPart(TargetCFrame) and :ReturnPart(Object) both use queued workspace:BulkMoveTo calls, it can actually be more performant to call these two methods every frame.

The following video calls :GetPart and :ReturnPart every frame, yet runs smooth as butter:

There is some lag from the recorder - ingame, I can run this smoothly at max FPS.

The place file used in the above video can be found here:
ObjectCache_Demo.rbxl
The demo file uses an outdated version of the module! Do not use the module from there.

Installation

Simply grab the file from Roblox marketplace: https://create.roblox.com/store/asset/18819618773/ObjectCache

Alternatively, Wally users can install the package through wally:

55 Likes
3 Likes

image

16 Likes

Dang, people using PartCache should probably update to this, if they work pretty much the same this feels really useful!

Will probably recommend to some voxel destruction module creators if I find it good haha

2 Likes

From personal benchmarking, ObjectCache seemed to have way less script activity
than PartCache.

This was the place file I benchmarked with, which is a copy of the original with the addition of PartCache and a copy of the original script local script, but using PartCache.

ObjectCache_Comparison.rbxl (60.2 KB)

7 Likes

This is a great module! I’ll be sure to use this for my future projects!

5 Likes

This will come in handy for replicating a ton of bullets (scary)
Thank you for making this!

4 Likes

do you guys ever think before posting

3 Likes

what is your problem?
image

3 Likes

i wasnt speaking to you? why u comin at me

1 Like

just asking why you were acting like this, I don’t wanna start an internet beef just because of a reply.

2 Likes

my bad i didnt mean to quote that guy, i was replying to the blueberry guy

3 Likes

What is the point of this? No context or anything.

1 Like

I didn’t see them talk about it, so I’m assuming they didn’t know something like this already exists. Additionally, people overuse the word ‘modern’ and ‘blazing’ so much. It doesn’t add much meaning to the newer one.

1 Like

I’m very much aware of PartCache, and specifically made this module as an improvement upon it. There’s more constructive ways to notify people about such things :stuck_out_tongue:

7 Likes

Yes but you provided zero context instead you just pasted a forum post directly. You’re being passive aggressive.

7 Likes

LMAO UR GETTING COOKED (rightfully so, criticizing people when you didnt even read the post)

1 Like

It’s probably because there was no proof provided that this was better than the other, I know other topics bluebxrrybot did this and it was completely valid.

He is right with one of his points, the post can probably do a little more to clarify how it’s better than the alternative instead of just saying it’s better and providing one statement why, clientcast was pretty well explained, but you’d probably be expected to know partcache before using this so I don’t really know lol

1 Like

It is already explained in the post — this is a more up-to-date version, using Roblox’s BulkMoveTo API to squeeze out the maximum performance. Additionally, it’s much smaller in terms of line count, and thus becomes easier to fork or modify for your own needs.

5 Likes

I’ve noticed when I’m using ReturnToCache, it’ll send the part that I wasn’t sending back causing issues D: