Handling mostly static config data: database, JSON file, `localcachePut`?

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 cache if we wanted to change the config for e.g. an event?

In our code, we can just check “return cache if exists, otherwise fetch from database and store into cache”.

Though I think since multiple Nakama server instances can exist, I would need to double check if there’s a way to invoke the cache invalidation RPC on all instances. Is what I’m describing actually possible and is there any “gotchas”?


For one example where I’m unsure what approach I should use:
I have “equipment templates” for each equipment item, which stores info about the equipment that is the same for all players who own said equipment item. Example:

{
  "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": "weapon_iron_sword"
}

The equipment templates ideally shouldn’t change unless releasing a new game version (server restart), but I can imagine a scenario where I realize I made a weapon too strong and need to adjust its equipment template stats to balance it.

So, would the best option be:

  • Store them in the database so they can be modified on-the-fly without server restart
  • Use localcachePut if it’s possible to invalidate cache via admin RPC without server restart, since the chance of equipment template being modified on-the-fly is rare, but not never.

Another use-case I’m wondering about is a shop config, which remains mostly static, but there’ll be occasional events that discount items or sell special items in the shop for a limited duration. Would I use a similar approach for this as with the equipment templates?