Looking at the API, the only available functions are:
localcacheGet(key: string)
localcachePut(key: string, value: any, ttl?: number)
localcacheDelete(key: string)
localcacheClear()
Is there no way to get an array of all cache keys? For example something like:
localcacheGetAllKeys()
If not, could it be introduced in a future Nakama version?
Hello @KamilDev ,
Can you elaborate on why you’d need to list all keys? What are you using the cache for?
Best.
I’d like to enumerate over them, for example get only cache keys that have a specific prefix (e.g. equipment_templates_v
) to clear all versions of cached equipment_templates
.
I’m still just experimenting, perhaps it’s not the best approach. Here are my related posts:
Overall, what’s a good way to go about handling versioning?
Lets take one example from my game. Equipment information, such as stats:
Equipment template:
{
"id": "weapon_iron_sword",
"type": "weapon",
"baseStats": {
"attack": 10,
"attackSpeed": 0,
},
"levelScaling": {
"baseMultiplier": 1,
"multiplierPerLevel": 0.1
},
}
For players actual inventory, it’s just:
{
"id": "1bdca98f-e1e4-4988-826f-10fa70b5f748",
"level": 1,
"rarity": "epic",
"templateId": "weap…
For handling mostly static config data, how do I go about determing if I should use:
Database (nk.storageRead)
JSON file (nk.fileRead)
Cache (nk.localcachePut)
I noticed that we could clear/invalidate cache using:
nk.localcacheClear() // all cache
nk.localcacheDelete("some-key") // specific cache
Theoretically, couldn’t we get the best of both worlds by utilizing database to store static configs, which gets put into cache at server startup, and then have an admin RPC that can clear the cach…