add TTLs object and update initialization

This commit is contained in:
2025-01-07 15:24:06 -08:00
parent f3ee83d195
commit d52eb4d655

View File

@@ -11,18 +11,26 @@ export interface ApiBasedRepositoryCache {
// To speed things up, implement caches for other data later // To speed things up, implement caches for other data later
} }
export class ApiBasedRepository implements GetterRepository { export interface ApiBasedRepositoryMillisecondTTLs {
private cache: ApiBasedRepositoryCache; etasForShuttleId: number,
etasForStopId: number,
}
constructor(initialCache: ApiBasedRepositoryCache | undefined = undefined) { const emptyCache: ApiBasedRepositoryCache = {
if (initialCache) { etasForShuttleId: {},
this.cache = initialCache; etasForStopId: {},
} else { }
this.cache = {
etasForShuttleId: {}, const defaultTtls: ApiBasedRepositoryMillisecondTTLs = {
etasForStopId: {}, etasForShuttleId: 10000,
} etasForStopId: 10000,
} }
export class ApiBasedRepository implements GetterRepository {
constructor(
private initialCache: ApiBasedRepositoryCache | undefined = emptyCache,
private ttls: ApiBasedRepositoryMillisecondTTLs = defaultTtls,
) {
} }
public async getEtaForShuttleAndStopId(shuttleId: string, stopId: string): Promise<IEta | null> { public async getEtaForShuttleAndStopId(shuttleId: string, stopId: string): Promise<IEta | null> {