> ## Documentation Index
> Fetch the complete documentation index at: https://docsuncv2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# cache.invalidate

Removes an Instance from the executor's instance cache so the next access to it returns a new value.

```luau theme={null}
cache.invalidate(instance: Instance): ()
```

The executor caches the Lua value handed back for each engine Instance, so repeated access to the same object returns the same value. `cache.invalidate` removes `instance` from that cache; the game object is not modified. The next time the engine hands that object to Lua, the access produces a new value instead of the one held before.

## Parameters

| Parameter  | Type                                                                           | Description                                     |
| ---------- | ------------------------------------------------------------------------------ | ----------------------------------------------- |
| `instance` | [`Instance`](https://create.roblox.com/docs/reference/engine/classes/Instance) | The Instance to drop from the executor's cache. |

## Returns

<code title="the function does not return a value.">void</code>

## Example

A game script caches a service reference and later checks whatever it is handed against that saved value. Keep your own working handle with `cloneref`, then `cache.invalidate` the service so the script's next fetch is a different Lua value than the one it stored.

<CodeGroup>
  ```luau Example 1 theme={null}
  <<<<<<< HEAD
  cache.invalidate(game:GetService("Players"))
  =======
  -- cache.invalidate(instance: Instance): ()
  >>>>>>> 50e30f53759b0538759af25c9b271514aa2c9290
  ```

  ```luau Example 2 theme={null}
  local Lighting = game:GetService("Lighting")

  -- an independent handle that still drives the real service
  local myHandle = cloneref(Lighting)
  cache.invalidate(Lighting)

  -- the next fetch is a new value, so it no longer matches the old one
  print(Lighting == game:GetService("Lighting")) -- false
  print(cache.iscached(Lighting))                -- false: dropped from the cache

  -- the clone is a separate value but still the same Instance
  print(myHandle == Lighting)                    -- false
  print(compareinstances(myHandle, Lighting))    -- true
  ```
</CodeGroup>

<Tip>
  Useful when testing object deletion, recreation, or bypassing anti-cheat wrapper caching.
</Tip>
