Skip to content

core.cache.localcache

This module provides local file-based cache functionality for persistent data storage during build operations.

TIP

To use this module, you need to import it first: import("core.cache.localcache")

localcache.set

  • Set a cache value with single key

Function Prototype

API

lua
localcache.set(cachename: <string>, key: <string>, value: <any>)

Parameter Description

ParameterDescription
cachenameRequired. Cache name string
keyRequired. Cache key string
valueRequired. Cache value (can be any Lua value)

Return Value

No return value

Usage

lua
import("core.cache.localcache")

-- Store a value with single key
localcache.set("mycache", "key1", {1, 2, 3})

localcache.get

  • Get a cache value with single key

Function Prototype

API

lua
localcache.get(cachename: <string>, key: <string>)

Parameter Description

ParameterDescription
cachenameRequired. Cache name string
keyRequired. Cache key string

Return Value

TypeDescription
anyReturns the cached value if found, nil otherwise

Usage

lua
import("core.cache.localcache")

-- Get a value with single key
local value = localcache.get("mycache", "key1")

localcache.set2

  • Set a cache value with two-level keys

Function Prototype

API

lua
localcache.set2(cachename: <string>, key1: <string>, key2: <string>, value: <any>)

Parameter Description

ParameterDescription
cachenameRequired. Cache name string
key1Required. First-level cache key string
key2Required. Second-level cache key string
valueRequired. Cache value (can be any Lua value)

Return Value

No return value

Usage

lua
import("core.cache.localcache")

-- Store a value with two-level keys
localcache.set2("mycache", "user", "name", "tboox")

localcache.get2

  • Get a cache value with two-level keys

Function Prototype

API

lua
localcache.get2(cachename: <string>, key1: <string>, key2: <string>)

Parameter Description

ParameterDescription
cachenameRequired. Cache name string
key1Required. First-level cache key string
key2Required. Second-level cache key string

Return Value

TypeDescription
anyReturns the cached value if found, nil otherwise

Usage

lua
import("core.cache.localcache")

-- Get a value with two-level keys
local name = localcache.get2("mycache", "user", "name")

localcache.clear

  • Clear cache entries

Function Prototype

API

lua
localcache.clear(cachename?: <string>)

Parameter Description

ParameterDescription
cachenameOptional. Cache name string. If omitted, clears all caches

Return Value

No return value

Usage

lua
import("core.cache.localcache")

-- Clear a specific cache
localcache.clear("mycache")

-- Clear all caches
localcache.clear()