Skip to main content

CacheService

Simple module for caching any data.

Functions​

CreateCache​

CacheService:CreateCache(
cacheName: string,--

The name of the cache

entryLimit: number?,--

Maximum number of entries (default 1000)

entryAgeLimit: number?--

Entry lifetime in seconds (default 3600)

) → Cache

Types

​

interface Cache {
EntryLimit: number--

Maximum number of entries the cache will hold

EntryAgeLimit: number--

Number of seconds entries are allowed to exist

Entries: {[string]: {
Data: any,
EntryTime: number
}}--

The cached entries

}

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

Set​

CacheService:Set(
cacheName: string,--

The name of the cache

index: string,--

The cache key

data: any--

The value to cache

) → ()

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

Get​

CacheService:Get(
cacheName: string,--

The name of the cache

index: string--

The cache key to look up

) → any?

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

GetOrAdd​

CacheService:GetOrAdd(
cacheName: string,--

The name of the cache

index: string,--

The cache key to look up

addCallback: function--

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"
    }
}