mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
add TTLs object and update initialization
This commit is contained in:
@@ -11,18 +11,26 @@ export interface ApiBasedRepositoryCache {
|
||||
// To speed things up, implement caches for other data later
|
||||
}
|
||||
|
||||
export class ApiBasedRepository implements GetterRepository {
|
||||
private cache: ApiBasedRepositoryCache;
|
||||
export interface ApiBasedRepositoryMillisecondTTLs {
|
||||
etasForShuttleId: number,
|
||||
etasForStopId: number,
|
||||
}
|
||||
|
||||
constructor(initialCache: ApiBasedRepositoryCache | undefined = undefined) {
|
||||
if (initialCache) {
|
||||
this.cache = initialCache;
|
||||
} else {
|
||||
this.cache = {
|
||||
etasForShuttleId: {},
|
||||
etasForStopId: {},
|
||||
}
|
||||
}
|
||||
const emptyCache: ApiBasedRepositoryCache = {
|
||||
etasForShuttleId: {},
|
||||
etasForStopId: {},
|
||||
}
|
||||
|
||||
const defaultTtls: ApiBasedRepositoryMillisecondTTLs = {
|
||||
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> {
|
||||
|
||||
Reference in New Issue
Block a user