{"id":"cg955gtr/partcache","name":"partcache","scope":"cg955gtr","platform":"roblox","description":"A linked list based part cache class written in strict Luau.","version":"1.1.2","latest":"1.1.2","versions":["1.0.0","1.0.1","1.0.2","1.1.0","1.1.1","1.1.2"],"license":"MIT","licenseRating":"safe","licenseCaveats":[],"licenseVerified":true,"dependencies":{},"integrity":"474d6b09bccce418591282cdc62c5da6f179c69d6fb913dfdfb51940e69d2b01","likes":0,"downloads":0,"install":"forest install cg955gtr/partcache","url":"https://forest.dev/p/roblox/cg955gtr/partcache","files":"https://api.forest.dev/ai/package/roblox/cg955gtr/partcache/files","readme":"# PartCache\r\nA linked list based part cache class written in strict Luau.\r\nThis can be used for when you are constantly creating parts, especially parts that only need to be there temporarily, such as:\r\n\r\n- Particle/sound emitting parts\r\n- Projectiles\r\n- Lightning effects\r\n\r\nCreating new parts and destroying them constantly, especially when rapid, is a very laggy process, and the part cache module will just CFrame the part when you pull a part from it. When the part is not needed anymore, you can return it to the cache, which will CFrame it further away again.\r\n\r\n> The linked list emphasis helps because a linked list is similar to an array, except its structured differently. A linked list is comprised of nodes, which each contains a value, and a pointer to the next node in the list. The list traverses down until the last node, which has no next node. This is useful for performance in this case, because when we are removing values from arrays, we have to shift every value above it down by one for each value removed. Linked lists allow you to extract the node, and just change the references, and save lots of CPU usage. While slightly more memory costly, the tradeoff is worth it\r\n\r\nThis module is compatible with FastCast, and is compatible with --!strict typechecking.\r\n\r\n## Installation\r\n\r\nYou can either install via wally, or by just grabbing the `init.luau` file from the repo.\r\n\r\n## Usage Example\r\n\r\n```luau\r\n--!strict\r\n\r\n--// This is a dumb usage example, but it will show you how it can be used.\r\n--// Get part cache module\r\nlocal PartCacheClass = require(path_to_module)\r\n\r\n--// Create a part cache\r\nlocal partCache = PartCacheClass.new(path_to_template_part_here, 50, path_to_storage_here)\r\n\r\n--// Pull 30 parts from the cache\r\nlocal partsInUse = partCache:GetParts(30)\r\n\r\n--// We now have pulled 30 parts from the cache that we can use\r\n--// Lets unanchor them and just throw them somewhere random from above\r\n\r\nlocal RNG = Random.new()\r\n\r\nfor _, part in PartsInUse do\r\n\tpart.Position = RNG:NextUnitVector() * RNG:NextNumber(0.5, 7.5)\r\n\tpart.Anchored = false\r\nend\r\n\r\n--// Wait a bit\r\ntask.wait(6)\r\n\r\n--// Return them to the cache\r\n--// Returning parts will also re-anchor them, so we don't have to do that here\r\npartCache:ReturnParts(partsInUse)\r\n\r\n--// We don't need the part cache anymore, we can destroy it now, save some memory!\r\n--// NOTE: This will also destroy parts in use. Beware!\r\npartCache:Destroy()\r\n\r\n--// You can use this in so many different ways, for re-using parts and not having to constantly clone and destroy them\r\n```\r\n","readmeTruncated":false}