Skip to main content

Cache

A named cache object returned by CacheService:CreateCache(). Stores key-value pairs with an age limit and entry limit.

Functions

Get

Cache:Get(
indexstring--

The cache key to look up

) → any?--

The cached value, or nil if missing or expired

Returns the cached value at the given index, or nil if the entry is missing or expired.

GetOrAdd

Cache:GetOrAdd(
indexstring,--

The cache key to look up

addCallbackfunction--

Called to produce the value if not cached

) → any?--

The cached or newly produced value

Returns the cached value at the given index. If it is missing or expired, calls addCallback to produce a value, caches it, and returns it.

Set

Cache:Set(
indexstring,--

The cache key to store the value under

dataany--

The value to cache

) → ()

Stores the given value at the specified index.

Show raw api
{
    "functions": [
        {
            "name": "Get",
            "desc": "Returns the cached value at the given index, or `nil` if the entry is\nmissing or expired.",
            "params": [
                {
                    "name": "index",
                    "desc": "The cache key to look up",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "The cached value, or nil if missing or expired",
                    "lua_type": "any?"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 100,
                "path": "src/shared/core/lib/CacheService.luau"
            }
        },
        {
            "name": "GetOrAdd",
            "desc": "Returns the cached value at the given index. If it is missing or expired,\ncalls `addCallback` to produce a value, caches it, and returns it.",
            "params": [
                {
                    "name": "index",
                    "desc": "The cache key to look up",
                    "lua_type": "string"
                },
                {
                    "name": "addCallback",
                    "desc": "Called to produce the value if not cached",
                    "lua_type": "function"
                }
            ],
            "returns": [
                {
                    "desc": "The cached or newly produced value",
                    "lua_type": "any?"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 122,
                "path": "src/shared/core/lib/CacheService.luau"
            }
        },
        {
            "name": "Set",
            "desc": "Stores the given value at the specified index.",
            "params": [
                {
                    "name": "index",
                    "desc": "The cache key to store the value under",
                    "lua_type": "string"
                },
                {
                    "name": "data",
                    "desc": "The value to cache",
                    "lua_type": "any"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 139,
                "path": "src/shared/core/lib/CacheService.luau"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "Cache",
    "desc": "A named cache object returned by [CacheService:CreateCache()](/api/CacheService#CreateCache). Stores\nkey-value pairs with an age limit and entry limit.",
    "source": {
        "line": 72,
        "path": "src/shared/core/lib/CacheService.luau"
    }
}