spark.saveLocal
function saveLocal(key: string, data: ArrayBuffer): Promise<void>Save data to local browser storage (IndexedDB) for offline access.
Stores data in the browser's IndexedDB, which provides:
- Persistent offline storage
- Large capacity (typically 50MB+ per origin)
- Fast access without network
- Automatic cleanup on browser clear data
Use this for:
- Caching trained model checkpoints
- Storing intermediate training states
- Offline-first application data
- Temporary computation results
Data is stored with a timestamp and can be retrieved later. Keys are unique per origin (domain).
Parameters
keystring- Unique identifier for this data (any string)
dataArrayBuffer- Data to store as ArrayBuffer (e.g., serialized model weights)
Returns
Promise<void>– Promise that resolves when data is storedExamples
// Save model checkpoint locally
const weights = torch.serialize(model.state_dict());
await spark.saveLocal('model-v1-best', weights);
// Save multiple checkpoints
await spark.saveLocal(`checkpoint-epoch-${epoch}`, stateBuffer);