cache.replace
Replaces a cached instance reference with another.
Syntax
cache.replace(instance: Instance, replacement: Instance) -> ()Parameters
| Parameter | Type | Description |
|---|---|---|
instance | Instance | The instance to replace |
replacement | Instance | The replacement instance |
Returns
This function does not return a value.
Description
cache.replace replaces an instance's cached reference. Existing references are unchanged, while future lookups return the replacement.
Example
local original = Instance.new("Folder")
original.Name = "CacheReplaceExample"
original.Parent = workspace
local replacement = Instance.new("Folder")
replacement.Name = "FakePart"
-- Replace the cached reference
cache.replace(original, replacement)
-- Looking up the original instance now returns the replacement
local lookup = workspace:FindFirstChild("CacheReplaceExample")
print(rawequal(lookup, replacement)) -- true
print(rawequal(original, replacement)) -- false
original:Destroy()
replacement:Destroy()Notes
- The original instance still exists
- References that were obtained before the replacement are unchanged
Related Functions
cache.invalidate- Remove from cachecache.iscached- Check if cached