Skip to content

Commit e5c1d47

Browse files
committed
refuse to setItem when number of chunks for new item exceeds maxTotalChunks config
1 parent 25ffa0a commit e5c1d47

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

packages/idb-cache/src/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,16 @@ export class IDBCache implements AsyncStorage {
552552
if (!this.dbReadyPromise) return;
553553
await this.ensureWorkerInitialized();
554554

555+
// Check if the new item's chunks would exceed maxTotalChunks config
556+
if (this.maxTotalChunks !== undefined) {
557+
const newItemChunks = Math.ceil(value.length / this.chunkSize);
558+
if (newItemChunks > this.maxTotalChunks) {
559+
throw new IDBCacheError(
560+
`Cannot store item: chunks needed (${newItemChunks}) exceeds maxTotalChunks (${this.maxTotalChunks})`
561+
);
562+
}
563+
}
564+
555565
if (this.priority === "low") {
556566
await waitForAnimationFrame();
557567
}

0 commit comments

Comments
 (0)