File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change 1- import { cache } from 'react' ;
21import matter from 'gray-matter' ;
32import { s } from 'hastscript' ;
43import yaml from 'js-yaml' ;
@@ -666,6 +665,7 @@ export async function getFileBySlug(slug: string): Promise<SlugFile> {
666665
667666 await cp ( assetsCacheDir , outdir , {
668667 recursive : true ,
668+ errorOnExist : false ,
669669 force : true ,
670670 } ) ;
671671 writeCacheFile ( cacheFile , JSON . stringify ( resultObj ) ) . catch ( e => {
@@ -676,9 +676,19 @@ export async function getFileBySlug(slug: string): Promise<SlugFile> {
676676 return resultObj ;
677677}
678678
679+ const fileBySlugCache = new Map < string , Promise < SlugFile > > ( ) ;
680+
679681/**
680682 * Cache the result of {@link getFileBySlug}.
681683 *
682684 * This is useful for performance when rendering the same file multiple times.
683685 */
684- export const getFileBySlugWithCache = cache ( getFileBySlug ) ;
686+ export function getFileBySlugWithCache ( slug : string ) : Promise < SlugFile > {
687+ let cached = fileBySlugCache . get ( slug ) ;
688+ if ( ! cached ) {
689+ cached = getFileBySlug ( slug ) ;
690+ fileBySlugCache . set ( slug , cached ) ;
691+ }
692+
693+ return cached ;
694+ }
You can’t perform that action at this time.
0 commit comments