Guide

ASK Cache Persistence

By default the ASK cache lives in process memory and dies with the process. For long-running services or agents that restart often, persist the cache to disk so the next process boots warm.

Manual save / load

// Before exit
await client.SaveAskCacheToDiskAsync("./ask-cache.json");

// On next startup
var client = new Client();
await client.LoadAskCacheFromDiskAsync("./ask-cache.json");

Note: LoadAskCacheFromDiskAsync merges entries into the in-memory cache without overwriting. Call ClearAskCache() first if you want a clean load.

Auto-persist

var client = new Client();
await client.EnableAutoPersistAsync("./ask-cache.json", loadIfExists: true);

// Every cache mutation now triggers a 2-second-debounced async write to the file.
// If the file existed and loadIfExists is true, it was loaded synchronously above.

// At shutdown — performs a final synchronous flush
client.DisableAutoPersist();

What's serialized

Loaders reject files with a different schema version loudly.

Security

The cache file contains derived ASK material in plaintext. Anyone who reads the file can decrypt envelopes for the recipients and sessions listed in it.

Protect the file with OS-level permissions:

chmod 600 ./ask-cache.json
  # Unix
icacls .\ask-cache.json /inheritance:r /grant:r "%USERNAME%":F
  # Windows

For higher-stakes environments, wrap the cache file in a Sessioned envelope to yourself before writing it (see Envelopes) — decrypt-then-load on boot.

See also