X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FSharedLRUCache.ts;h=49c06e90e53cb825433754b3e4a384df956631c4;hb=1185579a331f3484e8ed7882203d2e58466635dd;hp=a40de80293ad9090904be33cd5213e349bfe06fe;hpb=1ca780f9d385bcf96a016ab5ba57ca0f19c94b74;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/SharedLRUCache.ts b/src/charging-station/SharedLRUCache.ts index a40de802..49c06e90 100644 --- a/src/charging-station/SharedLRUCache.ts +++ b/src/charging-station/SharedLRUCache.ts @@ -1,8 +1,8 @@ import LRUCache from 'mnemonist/lru-map-with-delete'; -import ChargingStationConfiguration from '../types/ChargingStationConfiguration'; -import ChargingStationTemplate from '../types/ChargingStationTemplate'; -import Utils from '../utils/Utils'; +import { Bootstrap } from './internal'; +import type { ChargingStationConfiguration, ChargingStationTemplate } from '../types'; +import { Utils } from '../utils'; enum CacheType { CHARGING_STATION_TEMPLATE = 'chargingStationTemplate', @@ -11,12 +11,15 @@ enum CacheType { type CacheableType = ChargingStationTemplate | ChargingStationConfiguration; -export default class SharedLRUCache { +export class SharedLRUCache { private static instance: SharedLRUCache | null = null; private readonly lruCache: LRUCache; private constructor() { - this.lruCache = new LRUCache(1000); + this.lruCache = new LRUCache( + Bootstrap.getInstance().numberOfChargingStationTemplates + + Bootstrap.getInstance().numberOfChargingStations + ); } public static getInstance(): SharedLRUCache { @@ -79,18 +82,18 @@ export default class SharedLRUCache { } private getChargingStationConfigurationKey(hash: string): string { - return CacheType.CHARGING_STATION_CONFIGURATION + hash; + return `${CacheType.CHARGING_STATION_CONFIGURATION}${hash}`; } private getChargingStationTemplateKey(hash: string): string { - return CacheType.CHARGING_STATION_TEMPLATE + hash; + return `${CacheType.CHARGING_STATION_TEMPLATE}${hash}`; } private has(key: string): boolean { return this.lruCache.has(key); } - private get(key: string): CacheableType { + private get(key: string): CacheableType | undefined { return this.lruCache.get(key); } @@ -106,12 +109,12 @@ export default class SharedLRUCache { chargingStationConfiguration: ChargingStationConfiguration ): boolean { return ( - !Utils.isNullOrUndefined(chargingStationConfiguration?.configurationKey) && - !Utils.isNullOrUndefined(chargingStationConfiguration?.stationInfo) && - !Utils.isNullOrUndefined(chargingStationConfiguration?.configurationHash) && - !Utils.isEmptyArray(chargingStationConfiguration?.configurationKey) && - !Utils.isEmptyObject(chargingStationConfiguration?.stationInfo) && - !Utils.isEmptyString(chargingStationConfiguration?.configurationHash) + Utils.isNullOrUndefined(chargingStationConfiguration?.configurationKey) === false && + Utils.isNullOrUndefined(chargingStationConfiguration?.stationInfo) === false && + Utils.isNullOrUndefined(chargingStationConfiguration?.configurationHash) === false && + Utils.isNotEmptyArray(chargingStationConfiguration?.configurationKey) === true && + Utils.isEmptyObject(chargingStationConfiguration?.stationInfo) === false && + Utils.isNotEmptyString(chargingStationConfiguration?.configurationHash) === true ); } }