Skip to content

Commit b11642e

Browse files
committed
use cacheKey in generating chunk hash
1 parent 0d48b01 commit b11642e

File tree

2 files changed

+3
-16
lines changed

2 files changed

+3
-16
lines changed

packages/idb-cache/src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import type {
88
import {
99
generateChunkKey,
1010
openDatabase,
11-
computeChunkHash,
1211
parseChunkIndexFromKey,
1312
getAllChunkKeysForBaseKey,
1413
deterministicUUID,
@@ -419,7 +418,9 @@ export class IDBCache implements AsyncStorage {
419418
const chunk = value.slice(i, i + this.chunkSize);
420419
const chunkIndex = Math.floor(i / this.chunkSize);
421420

422-
const chunkHash = await computeChunkHash(chunk, this.cacheBuster);
421+
const chunkHash = await deterministicUUID(
422+
`${this.cacheKey}:${this.cacheBuster}:${chunk}`
423+
);
423424
const chunkKey = generateChunkKey(baseKey, chunkIndex, chunkHash);
424425
newChunkKeys.add(chunkKey);
425426

packages/idb-cache/src/utils.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,6 @@ export function generateChunkKey(
5555
return `${baseKey}-chunk-${String(chunkIndex).padStart(6, "0")}-${chunkHash}`;
5656
}
5757

58-
export async function computeChunkHash(
59-
chunk: string,
60-
cacheBuster: string
61-
): Promise<string> {
62-
const encoder = new TextEncoder();
63-
const data = encoder.encode(`${cacheBuster}:${chunk}`);
64-
const hashBuffer = await crypto.subtle.digest("SHA-512", data);
65-
const hashArray = Array.from(new Uint8Array(hashBuffer));
66-
const hashHex = hashArray
67-
.map((b) => b.toString(16).padStart(2, "0"))
68-
.join("");
69-
return generateUUIDFromHash(hashHex);
70-
}
71-
7258
export function parseChunkIndexFromKey(chunkKey: string): number {
7359
const parts = chunkKey.split("-chunk-");
7460
if (parts.length < 2) return -1;

0 commit comments

Comments
 (0)