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 keysExamples
// 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