| 366 | }, |
| 367 | |
| 368 | async getBytesInUse(keys) { |
| 369 | let totalBytes = 0; |
| 370 | const keysToCheck = !keys ? |
| 371 | Array.from(storageMap.keys()) : |
| 372 | Array.isArray(keys) ? keys : [keys]; |
| 373 | |
| 374 | for (const key of keysToCheck) { |
| 375 | if (storageMap.has(key)) { |
| 376 | // Rough byte calculation - stringify and count UTF-16 code units |
| 377 | const serialized = JSON.stringify({[key]: storageMap.get(key)}); |
| 378 | totalBytes += serialized.length * 2; // UTF-16 uses 2 bytes per character |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | return totalBytes; |
| 383 | }, |
| 384 | |
| 385 | async clear() { |
| 386 | storageMap.clear(); |