mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 16:00:32 +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
|
// 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) {
|
|
||||||
this.cache = initialCache;
|
|
||||||
} else {
|
|
||||||
this.cache = {
|
|
||||||
etasForShuttleId: {},
|
etasForShuttleId: {},
|
||||||
etasForStopId: {},
|
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> {
|
public async getEtaForShuttleAndStopId(shuttleId: string, stopId: string): Promise<IEta | null> {
|
||||||
|
|||||||
Reference in New Issue
Block a user