@@ -6,28 +6,21 @@ import { version } from './version.ts';
66const dummyFileDescriptor : FileDescriptor < any > = { key : '' , changed : true , notFound : true } ;
77
88export class CacheConsultant < T > {
9- private isEnabled : boolean ;
10- private cache : undefined | FileEntryCache < T > ;
9+ private cache : FileEntryCache < T > | undefined ;
10+ getFileDescriptor : ( filePath : string ) => FileDescriptor < T > = ( ) => dummyFileDescriptor ;
11+ reconcile : ( ) => void = ( ) => { } ;
1112
1213 constructor ( name : string , options : MainOptions ) {
13- this . isEnabled = options . isCache ;
14- if ( this . isEnabled ) {
15- const cacheName = `${ name . replace ( / [ ^ a - z 0 - 9 ] / g, '-' ) . replace ( / - * $ / , '' ) } -${ options . isProduction ? '-prod' : '' } -${ version } ` ;
16- this . cache = new FileEntryCache ( cacheName , options . cacheLocation ) ;
17- this . reconcile = timerify ( this . cache . reconcile ) . bind ( this . cache ) ;
18- this . getFileDescriptor = timerify ( this . cache . getFileDescriptor ) . bind ( this . cache ) ;
19- }
14+ if ( ! options . isCache ) return ;
15+ const cacheName = `${ name . replace ( / [ ^ a - z 0 - 9 ] / g, '-' ) . replace ( / - * $ / , '' ) } -${ options . isProduction ? '-prod' : '' } -${ version } ` ;
16+ this . cache = new FileEntryCache ( cacheName , options . cacheLocation ) ;
17+ this . getFileDescriptor = timerify ( this . cache . getFileDescriptor . bind ( this . cache ) ) ;
18+ this . reconcile = timerify ( this . cache . reconcile . bind ( this . cache ) ) ;
2019 }
21- public getFileDescriptor ( filePath : string ) : FileDescriptor < T > {
22- if ( this . isEnabled && this . cache ) return this . cache . getFileDescriptor ( filePath ) ;
23- return dummyFileDescriptor ;
24- }
25- public getCachedFile ( filePath : string ) : T | undefined {
26- if ( ! this . isEnabled || ! this . cache ) return undefined ;
20+
21+ getCachedFile ( filePath : string ) : T | undefined {
22+ if ( ! this . cache ) return undefined ;
2723 const fd = this . cache . getFileDescriptor ( filePath ) ;
2824 return ! fd . changed ? fd . meta ?. data : undefined ;
2925 }
30- public reconcile ( ) {
31- if ( this . isEnabled && this . cache ) this . cache . reconcile ( ) ;
32- }
3326}
0 commit comments