X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcharging-station%2FSharedLRUCache.ts;h=0d7a9dccec5fc04fbe19c4cbba386151d3af0265;hb=d4d65733e925dcc1b152eef88f3f03e6f25037c3;hp=49c06e90e53cb825433754b3e4a384df956631c4;hpb=60a743910478b70e39dcefa5e1b752ec8a93880e;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/SharedLRUCache.ts b/src/charging-station/SharedLRUCache.ts index 49c06e90..0d7a9dcc 100644 --- a/src/charging-station/SharedLRUCache.ts +++ b/src/charging-station/SharedLRUCache.ts @@ -1,22 +1,22 @@ -import LRUCache from 'mnemonist/lru-map-with-delete'; +import { LRUMapWithDelete as LRUCache } from 'mnemonist'; -import { Bootstrap } from './internal'; +import { Bootstrap } from './Bootstrap'; import type { ChargingStationConfiguration, ChargingStationTemplate } from '../types'; import { Utils } from '../utils'; enum CacheType { - CHARGING_STATION_TEMPLATE = 'chargingStationTemplate', - CHARGING_STATION_CONFIGURATION = 'chargingStationConfiguration', + chargingStationTemplate = 'chargingStationTemplate', + chargingStationConfiguration = 'chargingStationConfiguration', } -type CacheableType = ChargingStationTemplate | ChargingStationConfiguration; +type CacheValueType = ChargingStationTemplate | ChargingStationConfiguration; export class SharedLRUCache { private static instance: SharedLRUCache | null = null; - private readonly lruCache: LRUCache; + private readonly lruCache: LRUCache; private constructor() { - this.lruCache = new LRUCache( + this.lruCache = new LRUCache( Bootstrap.getInstance().numberOfChargingStationTemplates + Bootstrap.getInstance().numberOfChargingStations ); @@ -82,22 +82,22 @@ export class SharedLRUCache { } private getChargingStationConfigurationKey(hash: string): string { - return `${CacheType.CHARGING_STATION_CONFIGURATION}${hash}`; + return `${CacheType.chargingStationConfiguration}${hash}`; } private getChargingStationTemplateKey(hash: string): string { - return `${CacheType.CHARGING_STATION_TEMPLATE}${hash}`; + return `${CacheType.chargingStationTemplate}${hash}`; } private has(key: string): boolean { return this.lruCache.has(key); } - private get(key: string): CacheableType | undefined { + private get(key: string): CacheValueType | undefined { return this.lruCache.get(key); } - private set(key: string, value: CacheableType): void { + private set(key: string, value: CacheValueType): void { this.lruCache.set(key, value); } @@ -111,9 +111,12 @@ export class SharedLRUCache { return ( Utils.isNullOrUndefined(chargingStationConfiguration?.configurationKey) === false && Utils.isNullOrUndefined(chargingStationConfiguration?.stationInfo) === false && + Utils.isNullOrUndefined(chargingStationConfiguration?.automaticTransactionGenerator) === + false && Utils.isNullOrUndefined(chargingStationConfiguration?.configurationHash) === false && Utils.isNotEmptyArray(chargingStationConfiguration?.configurationKey) === true && Utils.isEmptyObject(chargingStationConfiguration?.stationInfo) === false && + Utils.isEmptyObject(chargingStationConfiguration?.automaticTransactionGenerator) === false && Utils.isNotEmptyString(chargingStationConfiguration?.configurationHash) === true ); }