@@ -523,17 +523,22 @@ export async function getFileBySlug(slug: string): Promise<SlugFile> {
523
523
) ;
524
524
}
525
525
526
- const cacheKey = md5 ( source ) ;
527
- const cacheFile = path . join ( CACHE_DIR , cacheKey ) ;
526
+ let cacheKey : string | null = null ;
527
+ let cacheFile : string | null = null ;
528
528
529
- try {
530
- const cached = await readCacheFile < SlugFile > ( cacheFile ) ;
531
- return cached ;
532
- } catch ( err ) {
533
- if ( err . code !== 'ENOENT' && err . code !== 'ABORT_ERR' ) {
534
- // If cache is corrupted, ignore and proceed
535
- // eslint-disable-next-line no-console
536
- console . warn ( `Failed to read MDX cache: ${ cacheFile } ` , err ) ;
529
+ if ( process . env . CI === '1' ) {
530
+ cacheKey = md5 ( source ) ;
531
+ cacheFile = path . join ( CACHE_DIR , cacheKey ) ;
532
+
533
+ try {
534
+ const cached = await readCacheFile < SlugFile > ( cacheFile ) ;
535
+ return cached ;
536
+ } catch ( err ) {
537
+ if ( err . code !== 'ENOENT' && err . code !== 'ABORT_ERR' ) {
538
+ // If cache is corrupted, ignore and proceed
539
+ // eslint-disable-next-line no-console
540
+ console . warn ( `Failed to read MDX cache: ${ cacheFile } ` , err ) ;
541
+ }
537
542
}
538
543
}
539
544
@@ -662,10 +667,12 @@ export async function getFileBySlug(slug: string): Promise<SlugFile> {
662
667
} ,
663
668
} ;
664
669
665
- writeCacheFile ( cacheFile , JSON . stringify ( resultObj ) ) . catch ( e => {
666
- // eslint-disable-next-line no-console
667
- console . warn ( `Failed to write MDX cache: ${ cacheFile } ` , e ) ;
668
- } ) ;
670
+ if ( cacheFile ) {
671
+ writeCacheFile ( cacheFile , JSON . stringify ( resultObj ) ) . catch ( e => {
672
+ // eslint-disable-next-line no-console
673
+ console . warn ( `Failed to write MDX cache: ${ cacheFile } ` , e ) ;
674
+ } ) ;
675
+ }
669
676
670
677
return resultObj ;
671
678
}
0 commit comments