import LRU from 'lru-cache' ; import superagent from 'superagent' ; import { userSvcAuthority , UserSvcPing } from 'authorities' ; import { InventoryCosmetics } from 'entities/inventory/cosmetics' ; export class InventoryService { param userId returns public static async GetCosmetics ( userId ) { try { const cachedCosmetics = cosmeticsCache . get ( userId ) ; if ( cachedCosmetics != null ) { return cachedCosmetics ; } if ( UserSvcPing . isAlive ( ) === false ) { return null ; } const res = await superagent . get ( `http://${ userSvcAuthority ( ) }/inventory/${ userId }/cosmetics` ) . accept ( 'json' ) ; if ( res . status !== 200 ) { return null ; } return res . body as InventoryCosmetics ; } catch ( error ) { await UserSvcPing . checkNow ( ) ; throw error ; } } } const cosmeticsCache = new LRU < number , InventoryCosmetics > ( { max : 100 , maxAge : 1000 * 15 } ) ;