Skip to main content

PartCache

PartCache V5.0 by Raildex // Xan the Dragon // Eti the Spirit

Creating parts is laggy, especially if they are supposed to be there for a split second and/or need to be made frequently. This module aims to resolve this lag by pre-creating the parts and CFraming them to a location far away and out of sight. When necessary, the user can get one of these parts and CFrame it to where they need, then return it to the cache when they are done with it.

According to someone instrumental in Roblox's backend technology, zeuxcg (https://devforum.roblox.com/u/zeuxcg/summary)

"CFrame is currently the only "fast" property in that you can change it every frame without really heavy code kicking in. Everything else is expensive." ~ https://devforum.roblox.com/t/event-that-fires-when-rendering-finishes/32954/19

This alone should ensure the speed granted by this module.

Functions

IsPartCache

static
PartCache.IsPartCache(
cacheany--

The value to check.

) → boolean--

Whether or not the value is a PartCache.

Checks if the given value is a PartCache.

new

static
PartCache.new(
configPartCacheConfig<T>--

The configuration for the cache.

) → PartCache--

The new cache.

Creates a new PartCache object.

GetInstancesInUse

PartCache:GetInstancesInUse() → {T}

Gets an array of all the PVInstances that have been pulled from the cache and are currently being used.

GetCacheParent

PartCache:GetCacheParent() → Instance

Gets the current Parent of the cached parts.

IsInUse

PartCache:IsInUse(objectPVInstance) → boolean

Checks whether or not the given object is currently being lent out.

BelongsTo

PartCache:BelongsTo(objectPVInstance) → boolean

Checks whether a given object belongs to this cache.

SetOnReturnFn

PartCache:SetOnReturnFn(fn((objPVInstance) → ())?) → ()

Sets the function that is called when a part is returned to the cache

Get

PartCache:Get() → PVInstance--

The PVInstance that was retrieved.

Gets a PVInstance from the cache, or creates one if no more are available.

Return

PartCache:Return(
objectPVInstance--

The object to return to the cache.

) → ()

Returns a PVInstance to the cache.

SetCacheParent

PartCache:SetCacheParent(
newParentInstance?--

The new parent of the parts in the cache. If nil, the DefaultCacheFolder will be used instead.

) → ()

Sets the parent of the parts in the cache.

Expand

PartCache:Expand(
numPartsnumber--

The number of parts to add to the cache. If nil, the ExpansionSize property will be used instead.

) → ()

Expands the cache by numParts parts.

Dispose

PartCache:Dispose() → ()

Destroys this cache entirely. Use this when you don't need this cache object anymore.

Show raw api
{
    "functions": [
        {
            "name": "IsPartCache",
            "desc": "Checks if the given value is a PartCache.",
            "params": [
                {
                    "name": "cache",
                    "desc": "The value to check.",
                    "lua_type": "any"
                }
            ],
            "returns": [
                {
                    "desc": "Whether or not the value is a PartCache.",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "tags": [
                "static"
            ],
            "source": {
                "line": 164,
                "path": "src/partcache/src/PartCache.lua"
            }
        },
        {
            "name": "new",
            "desc": "Creates a new PartCache object.",
            "params": [
                {
                    "name": "config",
                    "desc": "The configuration for the cache.",
                    "lua_type": "PartCacheConfig<T>"
                }
            ],
            "returns": [
                {
                    "desc": "The new cache.",
                    "lua_type": "PartCache"
                }
            ],
            "function_type": "static",
            "tags": [
                "static"
            ],
            "source": {
                "line": 177,
                "path": "src/partcache/src/PartCache.lua"
            }
        },
        {
            "name": "GetInstancesInUse",
            "desc": "Gets an array of all the PVInstances that have been pulled from the cache and are currently being used.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "{T}\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 238,
                "path": "src/partcache/src/PartCache.lua"
            }
        },
        {
            "name": "GetCacheParent",
            "desc": "Gets the current Parent of the cached parts.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Instance\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 246,
                "path": "src/partcache/src/PartCache.lua"
            }
        },
        {
            "name": "IsInUse",
            "desc": "Checks whether or not the given object is currently being lent out.",
            "params": [
                {
                    "name": "object",
                    "desc": "",
                    "lua_type": "PVInstance"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 254,
                "path": "src/partcache/src/PartCache.lua"
            }
        },
        {
            "name": "BelongsTo",
            "desc": "Checks whether a given object belongs to this cache.",
            "params": [
                {
                    "name": "object",
                    "desc": "",
                    "lua_type": "PVInstance"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 262,
                "path": "src/partcache/src/PartCache.lua"
            }
        },
        {
            "name": "SetOnReturnFn",
            "desc": "Sets the function that is called when a part is returned to the cache",
            "params": [
                {
                    "name": "fn",
                    "desc": "",
                    "lua_type": "((obj: PVInstance) -> ())?"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 274,
                "path": "src/partcache/src/PartCache.lua"
            }
        },
        {
            "name": "Get",
            "desc": "Gets a PVInstance from the cache, or creates one if no more are available.",
            "params": [],
            "returns": [
                {
                    "desc": "The PVInstance that was retrieved.",
                    "lua_type": "PVInstance"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 284,
                "path": "src/partcache/src/PartCache.lua"
            }
        },
        {
            "name": "Return",
            "desc": "Returns a PVInstance to the cache.",
            "params": [
                {
                    "name": "object",
                    "desc": "The object to return to the cache.",
                    "lua_type": "PVInstance"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 307,
                "path": "src/partcache/src/PartCache.lua"
            }
        },
        {
            "name": "SetCacheParent",
            "desc": "Sets the parent of the parts in the cache.",
            "params": [
                {
                    "name": "newParent",
                    "desc": "The new parent of the parts in the cache. If nil, the DefaultCacheFolder will be used instead.",
                    "lua_type": "Instance?"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 337,
                "path": "src/partcache/src/PartCache.lua"
            }
        },
        {
            "name": "Expand",
            "desc": "Expands the cache by numParts parts.",
            "params": [
                {
                    "name": "numParts",
                    "desc": "The number of parts to add to the cache. If nil, the ExpansionSize property will be used instead.",
                    "lua_type": "number"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 361,
                "path": "src/partcache/src/PartCache.lua"
            }
        },
        {
            "name": "Dispose",
            "desc": "Destroys this cache entirely. Use this when you don't need this cache object anymore.",
            "params": [],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 377,
                "path": "src/partcache/src/PartCache.lua"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "PartCache",
    "desc": "PartCache V5.0 by Raildex // Xan the Dragon // Eti the Spirit\n\nCreating parts is laggy, especially if they are supposed to be there for a split second and/or need to be made frequently.\nThis module aims to resolve this lag by pre-creating the parts and CFraming them to a location far away and out of sight.\nWhen necessary, the user can get one of these parts and CFrame it to where they need, then return it to the cache when they are done with it.\n\nAccording to someone instrumental in Roblox's backend technology, zeuxcg (https://devforum.roblox.com/u/zeuxcg/summary)\n\n*\"CFrame is currently the only \"fast\" property in that you can change it every frame without really heavy code kicking in. Everything else is expensive.\"*\n~ https://devforum.roblox.com/t/event-that-fires-when-rendering-finishes/32954/19\n\nThis alone should ensure the speed granted by this module.",
    "source": {
        "line": 18,
        "path": "src/partcache/src/PartCache.lua"
    }
}