N.cache (Client) β€” Local + Synced Data Storage

N.cache on the client side allows you to store, access, and sync small pieces of data between the client and server β€” such as player state, UI variables, or custom values.

It’s the lightweight β€œmemory” of NurJS that automatically synchronizes with the server when needed.

πŸ”Ή Basic Example

N.cache.set("currentMission", "bank_heist");
const mission = N.cache.get("currentMission");
mp.gui.chat.push(`🧩 Current mission: ${mission}`);

βœ… Output:

[N.cache] set "currentMission" = "bank_heist"
🧩 Current mission: bank_heistд

βš™οΈ Functions

🧩 N.cache.set(key, value, sync = true)

Stores a value in local cache. If sync = true, it also sends it to the server (NurRage:cache:clientSet).

N.cache.set("weather", "RAIN", true);
Parameter
Type
Default
Description

key

string

β€”

Unique cache key name

value

any

β€”

Value to store (string, number, object, etc.)

sync

boolean

true

Whether to sync with the server

βœ… Automatically logs to chat:

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

Retrieves a value from cache, or returns a default if missing.

Parameter
Type
Default
Description

key

string

β€”

Key to retrieve

def

any

null

Default value if not found

🧩 Server β†’ Client Sync

Whenever the server updates cache values, the client automatically receives updates via:

βœ… You can add listeners or handle it in your UI:

🧠 Internal Example

🧩 Example β€” Syncing Player State

πŸ”Ή Client

πŸ”Ή Server

βœ… Client instantly updates local cache.

πŸ’‘ Use Cases

Scenario
Example

UI State

N.cache.set("hudVisible", true)

Mission Progress

N.cache.set("missionStep", 3)

Player Variables

N.cache.set("seatbelt", true)

Server Sync

Auto-updates values like time, weather, health

βš™οΈ Internal Notes

  • Local data is stored in N.cache._data (Map object).

  • Supports any JSON-serializable value (string, number, object, array).

  • Server communication handled through NurRage:cache:clientSet and NurRage:cache:update.

  • Logging is automatic (for debug builds).

N.cache (client) is a lightweight and synchronized key-value store. It helps you quickly store and sync small pieces of state between client and server β€” ideal for UIs, missions, HUDs, and player data.

Last updated