N.cache — Shared Server-Client Cache

`N.cache` is a lightweight key-value storage system that keeps synchronized data between the **server** and **clients** in real time. It’s used to store and update global or player-specific values s

🔹 Overview

NurJS cache works on both sides:

Side
Role
Description

🖥️ Server

Master

Holds the authoritative cache map (N.cache._data).

💻 Client

Receiver

Receives live updates through the event NurRage:cache:update.

⚙️ Methods

N.cache.set(key, value, player?)

Stores a value and automatically sends it to all players (or one player if specified).

N.cache.set("weather", "EXTRASUNNY");
N.cache.set("serverTime", { hour: 12, minute: 0 });
N.cache.set("playerStats", { kills: 10, deaths: 2 }, player);

Parameter
Type
Description

key

string

Unique cache key.

value

any

Any serializable value (number, string, object).

player

object / null

Optional target player. If null, updates all clients.

✅ Features:

  • Automatically triggers NurRage:cache:update event on client(s).

  • Prints a debug message like

  • Great for broadcasting synchronized states (weather, time, event info, etc).

[N.cache] [SERVER] set weather = "EXTRASUNNY"

N.cache.get(key, def = null)

Returns the stored value from server memory.

Parameter
Type
Description

key

string

The key to retrieve.

def

any

Default value if the key doesn’t exist.

Returns the cached value or def if not found.

N.cache.clear()

Clears all cache data.

Deletes every key stored in N.cache._data.

🧩 Use Cases

🌤️ Sync Weather and Time

🕹️ Player-Specific Updates

⚡ Global Broadcasts

All connected clients receive the same data instantly.

⚠️ Notes

  • Cached values are stored in memory (not persistent between restarts).

  • Keys should be unique (e.g. "weather", "hud.money", "server.phase").

  • Use N.cache.clear() only when resetting server state or reloading systems.

N.cache provides real-time data synchronization between the server and clients. It’s ideal for keeping all players updated with the same values — like time, weather, UI states, or global events — without manual syncing.

Last updated