Skip to main content
torch.js has not been released yet.
torch.js logotorch.js logotorch.js
PlaygroundContact
Login
Documentation
IntroductionType SafetyTensor ExpressionsTensor IndexingEinsumEinopsAutogradTraining a ModelProfiling & MemoryPyTorch MigrationBest PracticesRuntimesPerformancePyTorch CompatibilityBenchmarksDType Coverage
torch.js· 2026
LegalTerms of UsePrivacy Policy
/
/
  1. docs
  2. Spark
  3. spark
  4. getLocalStorageInfo

spark.getLocalStorageInfo

function getLocalStorageInfo(): Promise<{ count: number; keys: string[]; }>

Get information about local browser storage usage.

Returns metadata about stored data without loading the actual data. Useful for displaying storage status to users or making storage decisions.

Does not include actual data sizes, just key count. For actual byte usage, you'd need to load and sum data sizes.

Returns

Promise<{ count: number; keys: string[]; }>– Promise resolving to object with: - count: Number of items stored - keys: Array of all stored keys

Examples

// Check storage status
const info = await spark.getLocalStorageInfo();
console.log(`Using ${info.count} local storage slots`);
console.log('Stored items:', info.keys);

// Display to user
const info = await spark.getLocalStorageInfo();
if (info.count > 10) {
  console.warn('Local storage is getting full, consider cleaning up');
}

// Auto-cleanup old checkpoints
const info = await spark.getLocalStorageInfo();
if (info.count > 5) {
  // Keep only the 3 most recent
  const toDelete = info.keys.slice(0, -3);
  for (const key of toDelete) {
    await spark.deleteLocal(key);
  }
}

See Also

  • listLocal - Get keys only
  • clearLocal - Clear all storage
Previous
getBaseUrl
Next
JsonRpcError