File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change 11export type WithCache < T > = T & { cache : Map < string , any > }
2- interface HasParent {
2+ interface FileLike {
3+ path : string ,
34 parent : { path : string }
45}
56
@@ -14,20 +15,21 @@ export const memoize = <T>(
1415 return cached
1516}
1617
17- export function filememoizeAsync < F extends HasParent , T > (
18+ export function filememoizeAsync < F extends FileLike , T > (
1819 fn : ( file : F , ...args : any [ ] ) => Promise < T > ,
1920) : WithCache < ( file : F , ...args : any [ ] ) => Promise < T > > {
20- const cache = new Map < string , Map < F , T > > ( )
21+ const cache = new Map < string , Map < string , T > > ( )
2122 const cached = async function ( this : any , file : F , ...args : any [ ] ) : Promise < T > {
2223 let subcache = cache . get ( file . parent . path )
2324 if ( ! subcache ) {
2425 subcache = new Map ( )
2526 cache . set ( file . parent . path , subcache )
2627 }
27- let val = subcache . get ( file )
28+ const key = `${ file . path } :${ args . join ( ',' ) } `
29+ let val = subcache . get ( key )
2830 if ( ! val ) {
2931 val = await fn . call ( this , file , ...args )
30- subcache . set ( file , val )
32+ subcache . set ( key , val )
3133 }
3234 return val
3335 }
You can’t perform that action at this time.
0 commit comments