Cache
Persistent snapshots of the in-browser filesystem.
The Strapkit filesystem lives in memory — it's gone the moment the page reloads. The cache layer captures a directory tree and stores it in persistent browser storage, keyed by an arbitrary string you control (typically a lockfile hash).
const lockHash = await sha256(await sk.read("/app/pnpm-lock.yaml"));
const hit = await sk.cacheRestore("/app", lockHash);
if (!hit) {
await sk.exec("cd /app && pnpm install");
await sk.cacheSave("/app", lockHash);
}How keys work
Each snapshot is identified by (path, key):
pathis the absolute filesystem path being captured. Different paths (e.g./appand/build) are stored independently and never collide.keyis any string you choose. Multiple keys for the same path coexist;cacheRestorematches on the exact key. Invalidation is up to the caller — change the key to bust the cache.
A typical pattern is to hash the project's lockfile (or some manifest) and use that as the key, so the cache automatically rotates when dependencies change.
What's preserved
A snapshot captures the contents of every regular file in the tree, plus directory structure and symlinks. File modes are preserved on restore. The on-disk format is private — don't read or modify cache entries directly.
Class methods
All four require a successful init() (called implicitly).
cacheSave(path, key)
cacheSave(path: string, key: string): Promise<void>Capture the tree at path and store it under key, overwriting any
existing entry for that pair. Symlinks are stored as links rather than
followed.
cacheRestore(path, key)
cacheRestore(path: string, key: string): Promise<boolean>Restore the snapshot for (path, key) into the filesystem at path.
Returns true on hit, false if no snapshot exists for that key.
Restore is idempotent: existing directories don't fault, and symlinks that already exist are replaced. If a file path in the snapshot collides with an existing directory, the file is skipped.
cacheHas(path, key)
cacheHas(path: string, key: string): Promise<boolean>Returns true iff a snapshot for (path, key) exists. Cheap — does not
read the snapshot.
cacheClear(path)
cacheClear(path: string): Promise<void>Removes every snapshot stored for path, regardless of key. Other paths'
caches are untouched.