import LRU , { Options } from "lru-cache" ; import { Language } from "./backend" ; export interface CacheKey { namespace : string ; locale : string ; } export interface Cache { get ( key ) : Promise < Language | null > ; set ( key , value ) : Promise < void > ; has ( key ) : Promise < boolean > ; } export class InMemoryLRUCache implements Cache { private cache : LRU < string , Language > ; constructor ( options = { } ) { this . cache = new LRU < string , Language > ( options ) ; } async set ( key , value ) { this . cache . set ( this . serialize ( key ) , value ) ; } async get ( key ) { return this . cache . get ( this . serialize ( key ) ) ?? null ; } async has ( key ) { return this . cache . has ( this . serialize ( key ) ) ; } private serialize ( cacheKey ) { return `${ cacheKey . locale }/${ cacheKey . namespace }` ; } }