import LRUCache from "lru-cache" ; import AuthToken from "./auth-token" ; see https export default class InstallationTokenCache { private readonly installationTokenCache : LRUCache < number , AuthToken > ; private static instance : InstallationTokenCache ; param maxTokens constructor ( maxTokens ) { this . installationTokenCache = new LRUCache < number , AuthToken > ( { max : maxTokens } ) ; } public static getInstance ( ) { if ( ! InstallationTokenCache . instance ) { InstallationTokenCache . instance = new InstallationTokenCache ( 1000 ) ; } return InstallationTokenCache . instance ; } param githubInstallationId param generateNewInstallationToken public async getInstallationToken ( githubInstallationId , generateNewInstallationToken ) { let token = this . installationTokenCache . get ( githubInstallationId ) ; if ( ! token || token . isAboutToExpire ( ) ) { token = await generateNewInstallationToken ( ) ; this . installationTokenCache . set ( githubInstallationId , token , token . millisUntilAboutToExpire ( ) ) ; } return token ; } public clear ( ) { this . installationTokenCache . reset ( ) ; } }