Skip to main content

CacheService

Simple module for caching any data.

Functions

CreateCache

CacheService:CreateCache(
cacheNamestring,--

The name of the cache

entryLimitnumber?,--

Maximum number of entries (default 1000)

entryAgeLimitnumber?--

Entry lifetime in seconds (default 3600)

) → Cache

Types

interface Cache {
EntryLimitnumber--

Maximum number of entries the cache will hold

EntryAgeLimitnumber--

Number of seconds entries are allowed to exist

Entries{[string]{
Dataany,
EntryTimenumber
}}--

The cached entries

}

Returns the named Cache, creating it if it does not already exist.

Set

CacheService:Set(
cacheNamestring,--

The name of the cache

indexstring,--

The cache key

dataany--

The value to cache

) → ()

Stores a value at the given index in the named cache.

Get

CacheService:Get(
cacheNamestring,--

The name of the cache

indexstring--

The cache key to look up

) → any?

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

GetOrAdd

CacheService:GetOrAdd(
cacheNamestring,--

The name of the cache

indexstring,--

The cache key to look up

addCallbackfunction--

Called to produce the value if not cached

) → any?

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

Show raw api
{
    "functions": [
        {
            "name": "CreateCache",
            "desc": "Returns the named `Cache`, creating it if it does not already exist.",
            "params": [
                {
                    "name": "cacheName",
                    "desc": "The name of the cache",
                    "lua_type": "string"
                },
                {
                    "name": "entryLimit",
                    "desc": "Maximum number of entries (default 1000)",
                    "lua_type": "number?"
                },
                {
                    "name": "entryAgeLimit",
                    "desc": "Entry lifetime in seconds (default 3600)",
                    "lua_type": "number?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Cache"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 158,
                "path": "src/shared/core/lib/CacheService.luau"
            }
        },
        {
            "name": "Set",
            "desc": "Stores a value at the given index in the named cache.",
            "params": [
                {
                    "name": "cacheName",
                    "desc": "The name of the cache",
                    "lua_type": "string"
                },
                {
                    "name": "index",
                    "desc": "The cache key",
                    "lua_type": "string"
                },
                {
                    "name": "data",
                    "desc": "The value to cache",
                    "lua_type": "any"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 175,
                "path": "src/shared/core/lib/CacheService.luau"
            }
        },
        {
            "name": "Get",
            "desc": "Returns the cached value at the given index, or `nil` if missing or expired.",
            "params": [
                {
                    "name": "cacheName",
                    "desc": "The name of the cache",
                    "lua_type": "string"
                },
                {
                    "name": "index",
                    "desc": "The cache key to look up",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "any?"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 186,
                "path": "src/shared/core/lib/CacheService.luau"
            }
        },
        {
            "name": "GetOrAdd",
            "desc": "Returns the cached value at the given index. If missing or expired, calls\n`addCallback` to produce a value, caches it, and returns it.",
            "params": [
                {
                    "name": "cacheName",
                    "desc": "The name of the cache",
                    "lua_type": "string"
                },
                {
                    "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": "",
                    "lua_type": "any?"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 199,
                "path": "src/shared/core/lib/CacheService.luau"
            }
        }
    ],
    "properties": [],
    "types": [
        {
            "name": "Cache",
            "desc": "",
            "fields": [
                {
                    "name": "EntryLimit",
                    "lua_type": "number",
                    "desc": "Maximum number of entries the cache will hold"
                },
                {
                    "name": "EntryAgeLimit",
                    "lua_type": "number",
                    "desc": "Number of seconds entries are allowed to exist"
                },
                {
                    "name": "Entries",
                    "lua_type": "{[string]: {Data: any, EntryTime: number}}",
                    "desc": "The cached entries"
                }
            ],
            "source": {
                "line": 29,
                "path": "src/shared/core/lib/CacheService.luau"
            }
        }
    ],
    "name": "CacheService",
    "desc": "Simple module for caching any data.",
    "source": {
        "line": 14,
        "path": "src/shared/core/lib/CacheService.luau"
    }
}