From the reference libraryFiveM

Shared

ox/ox_lib/Cache/Shared.mdx

Shared

A table containing cached function results, which may be constants or infrequently changed.

Default values

Adding new cached values

Values can be cached permanently, or added with a timeout.

cache(key, func, timeout)
  • key: string
    • a unique name to store and access the cached state.
  • func: function
    • a function to call when the cache is invalidated/empty.
  • timeout?: number
    • a timer in milliseconds to clear the cached state.
local i = 0

while true do
    Wait(1000)
    i += 1

    print(cache('test', function() return i end, 5000))
end

-- output:
> 1
> 1
> 1
> 1
> 1
> 6
> 6
> 6
Back to documentation