File tree Expand file tree Collapse file tree 1 file changed +11
-6
lines changed
packages/utils/src/lib/server/cache Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -19,11 +19,6 @@ type S3CacheOptions = {
19
19
defaultJitter ?: JitterMode | JitterFn ;
20
20
} ;
21
21
22
- type CacheEntry < V extends Uint8Array > = {
23
- value : V ;
24
- expiresAt ?: number ;
25
- } ;
26
-
27
22
export class S3Cache < V extends Uint8Array = Uint8Array > extends BaseCache < V > {
28
23
readonly #options: S3CacheOptions ;
29
24
readonly #client: S3 ;
@@ -146,10 +141,20 @@ export class S3Cache<V extends Uint8Array = Uint8Array> extends BaseCache<V> {
146
141
147
142
public async clearPattern ( pattern : string ) : Promise < void > {
148
143
const rx = new RegExp ( '^' + pattern . replace ( / \* / g, '.*' ) + '$' ) ;
144
+ const toDel : string [ ] = [ ] ;
149
145
for await ( const k of this . keys ( ) ) {
150
146
if ( rx . test ( k ) ) {
151
- await this . delete ( k ) ;
147
+ toDel . push ( this . buildKey ( k ) ) ;
152
148
}
153
149
}
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
+ }
154
159
}
155
160
}
You can’t perform that action at this time.
0 commit comments