Skip to content

Commit 9ac2d1a

Browse files
More consistent clearPattern
1 parent b831790 commit 9ac2d1a

File tree

1 file changed

+11
-6
lines changed
  • packages/utils/src/lib/server/cache

1 file changed

+11
-6
lines changed

packages/utils/src/lib/server/cache/s3.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ type S3CacheOptions = {
1919
defaultJitter?: JitterMode | JitterFn;
2020
};
2121

22-
type CacheEntry<V extends Uint8Array> = {
23-
value: V;
24-
expiresAt?: number;
25-
};
26-
2722
export class S3Cache<V extends Uint8Array = Uint8Array> extends BaseCache<V> {
2823
readonly #options: S3CacheOptions;
2924
readonly #client: S3;
@@ -146,10 +141,20 @@ export class S3Cache<V extends Uint8Array = Uint8Array> extends BaseCache<V> {
146141

147142
public async clearPattern(pattern: string): Promise<void> {
148143
const rx = new RegExp('^' + pattern.replace(/\*/g, '.*') + '$');
144+
const toDel: string[] = [];
149145
for await (const k of this.keys()) {
150146
if (rx.test(k)) {
151-
await this.delete(k);
147+
toDel.push(this.buildKey(k));
152148
}
153149
}
150+
while (toDel.length) {
151+
const chunk = toDel.splice(0, 1000);
152+
await this.#client.send(
153+
new DeleteObjectsCommand({
154+
Bucket: this.#options.bucket,
155+
Delete: { Objects: chunk.map((Key) => ({ Key })) },
156+
}),
157+
);
158+
}
154159
}
155160
}

0 commit comments

Comments
 (0)