Cache & Remember/Recall

OcaltQL has two persistence mechanisms that survive across script executions. REMEMBER stores data permanently until explicitly deleted. CACHE stores data temporarily with a time-to-live that expires automatically. Both are key-value stores scoped to your account.

REMEMBER

REMEMBER stores a value under a key permanently. It persists until FORGET deletes it. It survives across all executions, sessions, and requests.

Store a Value
REMEMBER "username" AS "Alice"
AFTER REMEMBER "count" AS 42
AFTER STRING "secret" SET ?val
AFTER REMEMBER "token" AS ?val

RECALL

RECALL retrieves a stored value by key into a variable. Returns null if the key does not exist or has been forgotten.

Retrieve a Value
RECALL "username" SET ?name
AFTER EMIT ?name
Retrieve a Value — Not Found
RECALL "missing" SET ?nothing
AFTER EMIT ?nothing
(* Output: null *)

FORGET

FORGET permanently deletes a stored key. After a FORGET, RECALL on that key returns null.

Delete a Stored Key
FORGET "username"

CACHE

CACHE STORE saves a value under a key with a TTL — time to live. When the TTL expires the value is automatically removed. CACHE GET retrieves the value while it is still alive, or returns null if it has expired or never existed. CACHE REMOVE deletes it early before the TTL runs out.

Store with TTL
CACHE STORE "session" AS "active" TTL 1 HOUR
AFTER CACHE STORE "temp" AS "data" TTL 5 MINUTES
AFTER CACHE STORE "quick" AS "value" TTL 30 SECONDS
Retrieve from Cache
CACHE GET "session" SET ?status
AFTER EMIT ?status
Retrieve from Cache — Expired or Missing
CACHE GET "expired" SET ?gone
AFTER EMIT ?gone
(* Output: null *)
Remove Cache Entry Early
CACHE REMOVE "session"

REMEMBER vs CACHE

The distinction is simple — use REMEMBER when the data must survive indefinitely. Use CACHE when the data has a natural expiry and should clean itself up automatically.

Side by Side
REMEMBER "config" AS "dark_mode"
AFTER CACHE STORE "session_id" AS "abc123" TTL 1 HOUR

Storing Structured Data

Both REMEMBER and CACHE store strings. To persist objects, cast them to JSON first with CAST ?obj AS JSON, then parse back on retrieval with PARSE ?raw AS JSON.

Store and Recall an Object
NEW OBJECT SET ?settings
AFTER SET ?settings("theme") AS "dark"
AFTER SET ?settings("lang") AS "en"
AFTER CAST ?settings AS JSON SET ?json
AFTER REMEMBER "app_settings" AS ?json
AFTER RECALL "app_settings" SET ?raw
AFTER PARSE ?raw AS JSON SET ?parsed
AFTER EMIT ?parsed("theme")
(* Output: dark *)
REMEMBER is permanent key-value storage. CACHE is TTL-based key-value storage. Both persist across executions. Neither is session-scoped

Where they live: REMEMBER keys and CACHE entries are held in your own namespace, in the reserved /root/.ql area described on Namespace Storage. Neither is capped by count.