File tree Expand file tree Collapse file tree 1 file changed +12
-13
lines changed
Expand file tree Collapse file tree 1 file changed +12
-13
lines changed Original file line number Diff line number Diff line change @@ -694,22 +694,21 @@ export async function getFileBySlug(slug: string): Promise<SlugFile> {
694694 return resultObj ;
695695}
696696
697- const fileBySlugCache = new Map < string , Promise < SlugFile > > ( ) ;
697+
698698
699699/**
700700 * Cache the result of {@link getFileBySlug}.
701701 *
702702 * This is useful for performance when rendering the same file multiple times.
703703 */
704- export function getFileBySlugWithCache ( slug : string ) : Promise < SlugFile > {
705- if ( process . env . NODE_ENV === 'development' ) {
706- // Bypass the cache in development to ensure hot reload works for MDX files
707- return getFileBySlug ( slug ) ;
708- }
709- let cached = fileBySlugCache . get ( slug ) ;
710- if ( ! cached ) {
711- cached = getFileBySlug ( slug ) ;
712- fileBySlugCache . set ( slug , cached ) ;
713- }
714- return cached ;
715- }
704+ export const getFileBySlugWithCache : ( slug : string ) => Promise < SlugFile > =
705+ process . env . NODE_ENV === 'development'
706+ ? getFileBySlug
707+ : ( slug : string ) => {
708+ let cached = fileBySlugCache . get ( slug ) ;
709+ if ( ! cached ) {
710+ cached = getFileBySlug ( slug ) ;
711+ fileBySlugCache . set ( slug , cached ) ;
712+ }
713+ return cached ;
714+ } ;
You can’t perform that action at this time.
0 commit comments