import BaseError from '../exception/BaseError';
import { ChargePointErrorCode } from '../types/ocpp/ChargePointErrorCode';
import { ChargePointStatus } from '../types/ocpp/ChargePointStatus';
-import { ChargingStationCache } from './ChargingStationCache';
import ChargingStationConfiguration from '../types/ChargingStationConfiguration';
import { ChargingStationConfigurationUtils } from './ChargingStationConfigurationUtils';
import ChargingStationInfo from '../types/ChargingStationInfo';
import OCPPRequestService from './ocpp/OCPPRequestService';
import { OCPPVersion } from '../types/ocpp/OCPPVersion';
import PerformanceStatistics from '../performance/PerformanceStatistics';
+import SharedLRUCache from './SharedLRUCache';
import { SupervisionUrlDistribution } from '../types/ConfigurationData';
import Utils from '../utils/Utils';
import crypto from 'crypto';
private autoReconnectRetryCount: number;
private stopped: boolean;
private templateFileWatcher!: fs.FSWatcher;
- private readonly cache: ChargingStationCache;
+ private readonly sharedLRUCache: SharedLRUCache;
private automaticTransactionGenerator!: AutomaticTransactionGenerator;
private webSocketPingSetInterval!: NodeJS.Timeout;
this.stopped = false;
this.wsConnectionRestarted = false;
this.autoReconnectRetryCount = 0;
- this.cache = ChargingStationCache.getInstance();
+ this.sharedLRUCache = SharedLRUCache.getInstance();
this.authorizedTagsCache = AuthorizedTagsCache.getInstance();
this.connectors = new Map<number, ConnectorStatus>();
this.requests = new Map<string, CachedRequest>();
this.templateFile
} file have changed, reload`
);
- this.cache.deleteChargingStationTemplate(this.stationInfo?.templateHash);
+ this.sharedLRUCache.deleteChargingStationTemplate(this.stationInfo?.templateHash);
// Initialize
this.initialize();
// Restart the ATG
if (this.getEnableStatistics()) {
this.performanceStatistics.stop();
}
- this.cache.deleteChargingStationConfiguration(this.configurationFileHash);
+ this.sharedLRUCache.deleteChargingStationConfiguration(this.configurationFileHash);
this.templateFileWatcher.close();
- this.cache.deleteChargingStationTemplate(this.stationInfo?.templateHash);
+ this.sharedLRUCache.deleteChargingStationTemplate(this.stationInfo?.templateHash);
this.bootNotificationResponse = null;
parentPort.postMessage({
id: ChargingStationWorkerMessageEvents.STOPPED,
private getTemplateFromFile(): ChargingStationTemplate | null {
let template: ChargingStationTemplate = null;
try {
- if (this.cache.hasChargingStationTemplate(this.stationInfo?.templateHash)) {
- template = this.cache.getChargingStationTemplate(this.stationInfo.templateHash);
+ if (this.sharedLRUCache.hasChargingStationTemplate(this.stationInfo?.templateHash)) {
+ template = this.sharedLRUCache.getChargingStationTemplate(this.stationInfo.templateHash);
} else {
const measureId = `${FileType.ChargingStationTemplate} read`;
const beginId = PerformanceStatistics.beginMeasure(measureId);
.createHash(Constants.DEFAULT_HASH_ALGORITHM)
.update(JSON.stringify(template))
.digest('hex');
- this.cache.setChargingStationTemplate(template);
+ this.sharedLRUCache.setChargingStationTemplate(template);
}
} catch (error) {
FileUtils.handleFileException(
let configuration: ChargingStationConfiguration = null;
if (this.configurationFile && fs.existsSync(this.configurationFile)) {
try {
- if (this.cache.hasChargingStationConfiguration(this.configurationFileHash)) {
- configuration = this.cache.getChargingStationConfiguration(this.configurationFileHash);
+ if (this.sharedLRUCache.hasChargingStationConfiguration(this.configurationFileHash)) {
+ configuration = this.sharedLRUCache.getChargingStationConfiguration(
+ this.configurationFileHash
+ );
} else {
const measureId = `${FileType.ChargingStationConfiguration} read`;
const beginId = PerformanceStatistics.beginMeasure(measureId);
) as ChargingStationConfiguration;
PerformanceStatistics.endMeasure(measureId, beginId);
this.configurationFileHash = configuration.configurationHash;
- this.cache.setChargingStationConfiguration(configuration);
+ this.sharedLRUCache.setChargingStationConfiguration(configuration);
}
} catch (error) {
FileUtils.handleFileException(
fs.writeFileSync(fileDescriptor, JSON.stringify(configurationData, null, 2), 'utf8');
fs.closeSync(fileDescriptor);
PerformanceStatistics.endMeasure(measureId, beginId);
- this.cache.deleteChargingStationConfiguration(this.configurationFileHash);
+ this.sharedLRUCache.deleteChargingStationConfiguration(this.configurationFileHash);
this.configurationFileHash = configurationHash;
- this.cache.setChargingStationConfiguration(configurationData);
+ this.sharedLRUCache.setChargingStationConfiguration(configurationData);
} else {
logger.debug(
`${this.logPrefix()} Not saving unchanged charging station configuration file ${
type CacheableType = ChargingStationTemplate | ChargingStationConfiguration;
-export class ChargingStationCache {
- private static instance: ChargingStationCache | null = null;
+export default class SharedLRUCache {
+ private static instance: SharedLRUCache | null = null;
private readonly lruCache: LRUCache<string, CacheableType>;
private constructor() {
this.lruCache = new LRUCache<string, CacheableType>(1000);
}
- public static getInstance(): ChargingStationCache {
- if (!ChargingStationCache.instance) {
- ChargingStationCache.instance = new ChargingStationCache();
+ public static getInstance(): SharedLRUCache {
+ if (!SharedLRUCache.instance) {
+ SharedLRUCache.instance = new SharedLRUCache();
}
- return ChargingStationCache.instance;
+ return SharedLRUCache.instance;
}
public hasChargingStationConfiguration(chargingStationConfigurationHash: string): boolean {