mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
update cache and ttls interface
This commit is contained in:
@@ -11,15 +11,16 @@ export interface ApiBasedRepositoryCache {
|
||||
stopsBySystemId?: {
|
||||
[systemId: string]: IStop[],
|
||||
},
|
||||
shuttlesByShuttleId?: {
|
||||
[shuttleId: string]: IShuttle[],
|
||||
shuttleByShuttleId?: {
|
||||
[shuttleId: string]: IShuttle,
|
||||
},
|
||||
// To speed things up, implement caches for other data later
|
||||
}
|
||||
|
||||
export interface ApiBasedRepositoryMillisecondTTLs {
|
||||
etasForShuttleId: number,
|
||||
etasForStopId: number,
|
||||
etasForShuttleId?: number,
|
||||
etasForStopId?: number,
|
||||
shuttleByShuttleId?: number,
|
||||
}
|
||||
|
||||
const emptyCache: ApiBasedRepositoryCache = {
|
||||
@@ -33,10 +34,13 @@ const defaultTtls: ApiBasedRepositoryMillisecondTTLs = {
|
||||
}
|
||||
|
||||
export class ApiBasedRepository implements GetterRepository {
|
||||
private cache: ApiBasedRepositoryCache;
|
||||
|
||||
constructor(
|
||||
private initialCache: ApiBasedRepositoryCache | undefined = emptyCache,
|
||||
initialCache: ApiBasedRepositoryCache | undefined = emptyCache,
|
||||
private ttls: ApiBasedRepositoryMillisecondTTLs = defaultTtls,
|
||||
) {
|
||||
this.cache = initialCache;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,8 +64,8 @@ export class ApiBasedRepository implements GetterRepository {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (this.initialCache?.etasForStopId !== undefined) {
|
||||
const etas = this.initialCache.etasForStopId[systemId];
|
||||
if (this.cache?.etasForStopId !== undefined) {
|
||||
const etas = this.cache.etasForStopId[systemId];
|
||||
const foundEta = etas.find((eta) => eta.stopId === stopId);
|
||||
if (foundEta) {
|
||||
return foundEta;
|
||||
|
||||
Reference in New Issue
Block a user