import { CacheEngine } from "./types" ; export type CacheEngineCreator = ( ) => CacheEngine | null ; const creators = [ ] ; export const registerCacheEngineCreator = ( fn ) => { creators . push ( fn ) ; } ; const initialized = false ; export const detectCacheEngine = ( ) : CacheEngine => { if ( ! initialized ) { ( process . env . LOAD_MEDIAURL_CACHE_MODULE ?? "" ) . split ( / +/ ) . map ( ( module ) => module . replace ( / +/g , "" ) ) . filter ( ( module ) => module ) . forEach ( ( module ) => { try { require ( module ) ; } catch ( error ) { throw new Error ( `Failed loading MediaURL cache module "${ module }": ${ error . message }` ) ; } } ) ; } let engine = null ; for ( const fn of creators ) { engine = fn ( ) ; if ( engine ) return engine ; } return new ( require ( "./engines/memory" ) . MemoryCache ) ( ) ; } ;