import LRUCache from 'mnemonist/lru-map-with-delete';
-import ChargingStationConfiguration from '../types/ChargingStationConfiguration';
-import ChargingStationTemplate from '../types/ChargingStationTemplate';
+import { Bootstrap } from '../internal';
+import type { ChargingStationConfiguration } from '../types/ChargingStationConfiguration';
+import type { ChargingStationTemplate } from '../types/ChargingStationTemplate';
import Utils from '../utils/Utils';
enum CacheType {
private readonly lruCache: LRUCache<string, CacheableType>;
private constructor() {
- this.lruCache = new LRUCache<string, CacheableType>(1000);
+ this.lruCache = new LRUCache<string, CacheableType>(
+ Bootstrap.getInstance().numberOfChargingStationTemplates +
+ Bootstrap.getInstance().numberOfChargingStations
+ );
}
public static getInstance(): SharedLRUCache {
- if (!SharedLRUCache.instance) {
+ if (SharedLRUCache.instance === null) {
SharedLRUCache.instance = new SharedLRUCache();
}
return SharedLRUCache.instance;
}
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);
}
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.isEmptyArray(chargingStationConfiguration?.configurationKey) === false &&
+ Utils.isEmptyObject(chargingStationConfiguration?.stationInfo) === false &&
+ Utils.isEmptyString(chargingStationConfiguration?.configurationHash) === false
);
}
}