Skip to content

Commit 2c279c1

Browse files
committed
split cache per nodered id
1 parent fa01f5f commit 2c279c1

7 files changed

Lines changed: 20 additions & 19 deletions

File tree

OpenFlowNodeRED/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openflow-nodered",
3-
"version": "1.1.22",
3+
"version": "1.1.23",
44
"description": "Simple wrapper around NodeRed, RabbitMQ and MongoDB to support a more scaleable NodeRed implementation.\r Also the \"backend\" for [OpenRPA](https://github.com/skadefro/OpenRPA)",
55
"main": "index.js",
66
"scripts": {

OpenFlowNodeRED/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { Config } from "./Config";
99
import { Crypt } from "./nodeclient/Crypt";
1010
import { FileSystemCache } from "openflow-api";
1111

12-
const backupStore = new FileSystemCache(path.join(Config.logpath, '.cache'));
1312
const logger: winston.Logger = Logger.configure();
1413
logger.info("starting openflow nodered");
1514

@@ -30,6 +29,7 @@ rejectionEmitter.on("rejectionHandled", (error, promise) => {
3029
let server: http.Server = null;
3130
(async function (): Promise<void> {
3231
try {
32+
const backupStore = new FileSystemCache(path.join(Config.logpath, '.cache-' + Config.nodered_id));
3333
const filename: string = Config.nodered_id + "_flows.json";
3434
const json = await backupStore.get(filename, null);
3535
if (!NoderedUtil.IsNullEmpty(json) && Config.allow_start_from_cache) {

OpenFlowNodeRED/src/node-red-contrib-auth-saml.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Logger } from "./Logger";
88
import { Config } from "./Config";
99
export const logger = Logger.configure();
1010
import { FileSystemCache } from "openflow-api";
11-
const backupStore = new FileSystemCache(path.join(Config.logpath, '.cache'));
11+
1212
// tslint:disable-next-line: class-name
1313
export class samlauthstrategyoptions {
1414
public callbackUrl: string = "auth/strategy/callback/";
@@ -75,6 +75,7 @@ export class noderedcontribauthsaml {
7575
// if anything throws, we retry
7676
var metadata: any = await retry(async bail => {
7777
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
78+
const backupStore = new FileSystemCache(path.join(Config.logpath, '.cache-' + Config.nodered_id));
7879
var reader: any = await fetch({ url, backupStore });
7980
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "1";
8081
if (reader === null || reader === undefined) { bail(new Error("Failed getting result")); return; }

OpenFlowNodeRED/src/node-red-contrib-openflow-storage.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { Config } from "./Config";
77
import { WebSocketClient, NoderedUtil, Base } from "openflow-api";
88
import * as nodered from "node-red";
99
import { FileSystemCache } from "openflow-api";
10-
const backupStore = new FileSystemCache(path.join(Config.logpath, '.cache'));
1110
export class noderednpmrc {
1211
public _id: string;
1312
public _type: string = "npmrc";
@@ -19,6 +18,7 @@ export class noderednpmrc {
1918
// tslint:disable-next-line: class-name
2019
export class noderedcontribopenflowstorage {
2120

21+
private backupStore: FileSystemCache = null;
2222
private socket: WebSocketClient = null;
2323
private _logger: winston.Logger;
2424
private settings: nodered_settings = null;
@@ -37,6 +37,7 @@ export class noderedcontribopenflowstorage {
3737
this.RED = nodered;
3838
this._logger = logger;
3939
this.socket = socket;
40+
this.backupStore = new FileSystemCache(path.join(Config.logpath, '.cache-' + Config.nodered_id));
4041
this.getFlows = (this._getFlows.bind(this));
4142
this.saveFlows = (this._saveFlows.bind(this));
4243
this.getCredentials = (this._getCredentials.bind(this));
@@ -371,21 +372,21 @@ export class noderedcontribopenflowstorage {
371372
}
372373
const filename: string = Config.nodered_id + "_flows.json";
373374
if (result.length == 0) {
374-
const json = await backupStore.get<string>(filename, null);
375+
const json = await this.backupStore.get<string>(filename, null);
375376
if (!NoderedUtil.IsNullEmpty(json)) {
376377
this._flows = JSON.parse(json);
377378
result = this._flows;
378379
}
379380
} else {
380-
await backupStore.set(filename, JSON.stringify(result));
381+
await this.backupStore.set(filename, JSON.stringify(result));
381382
}
382383
return result;
383384
}
384385
public async _saveFlows(flows: any[]): Promise<void> {
385386
try {
386387
this._logger.silly("noderedcontribopenflowstorage::_saveFlows");
387388
const filename: string = Config.nodered_id + "_flows.json";
388-
await backupStore.set(filename, JSON.stringify(flows));
389+
await this.backupStore.set(filename, JSON.stringify(flows));
389390
if (WebSocketClient.instance.isConnected()) {
390391
this.last_reload = new Date();
391392
var result = await NoderedUtil.Query("nodered", { _type: "flow", nodered_id: Config.nodered_id }, null, null, 1, 0, null);
@@ -433,22 +434,22 @@ export class noderedcontribopenflowstorage {
433434
}
434435
const filename: string = Config.nodered_id + "_credentials";
435436
if (cred.length == 0) {
436-
let json = await backupStore.get<string>(filename, null);
437+
let json = await this.backupStore.get<string>(filename, null);
437438
if (!NoderedUtil.IsNullEmpty(json)) {
438439
json = noderedcontribopenflowstorage.decrypt(json);
439440
this._credentials = JSON.parse(json);
440441
cred = this._credentials;
441442
}
442443
} else {
443-
await backupStore.set(filename, noderedcontribopenflowstorage.encrypt(JSON.stringify(cred)));
444+
await this.backupStore.set(filename, noderedcontribopenflowstorage.encrypt(JSON.stringify(cred)));
444445
}
445446
return cred;
446447
}
447448
public async _saveCredentials(credentials: any): Promise<void> {
448449
try {
449450
this._logger.silly("noderedcontribopenflowstorage::_saveCredentials");
450451
const filename: string = Config.nodered_id + "_credentials";
451-
await backupStore.set(filename, noderedcontribopenflowstorage.encrypt(JSON.stringify(credentials)));
452+
await this.backupStore.set(filename, noderedcontribopenflowstorage.encrypt(JSON.stringify(credentials)));
452453
if (WebSocketClient.instance.isConnected()) {
453454
this.last_reload = new Date();
454455
var result = await NoderedUtil.Query("nodered", { _type: "credential", nodered_id: Config.nodered_id }, null, null, 1, 0, null);
@@ -517,7 +518,7 @@ export class noderedcontribopenflowstorage {
517518
}
518519
if (settings == null) {
519520
settings = {};
520-
const json = await backupStore.get<string>(filename, null);
521+
const json = await this.backupStore.get<string>(filename, null);
521522
if (!NoderedUtil.IsNullEmpty(json)) {
522523
this._settings = JSON.parse(json);
523524
settings = this._settings;
@@ -569,7 +570,7 @@ export class noderedcontribopenflowstorage {
569570
}
570571
}
571572
this._settings = settings;
572-
await backupStore.set(filename, JSON.stringify(settings));
573+
await this.backupStore.set(filename, JSON.stringify(settings));
573574
}
574575
try {
575576
if (this.firstrun) {
@@ -722,7 +723,7 @@ export class noderedcontribopenflowstorage {
722723
try {
723724
this._logger.silly("noderedcontribopenflowstorage::_saveSettings");
724725
const filename: string = Config.nodered_id + "_settings";
725-
await backupStore.set(filename, JSON.stringify(settings));
726+
await this.backupStore.set(filename, JSON.stringify(settings));
726727
if (WebSocketClient.instance.isConnected()) {
727728
this.last_reload = new Date();
728729
var result = await NoderedUtil.Query("nodered", { _type: "setting", nodered_id: Config.nodered_id }, null, null, 1, 0, null);
@@ -761,19 +762,19 @@ export class noderedcontribopenflowstorage {
761762
}
762763
const filename: string = Config.nodered_id + "_sessions";
763764
if (item == null || item.length == 0) {
764-
const json = await backupStore.get<string>(filename, null);
765+
const json = await this.backupStore.get<string>(filename, null);
765766
if (!NoderedUtil.IsNullEmpty(json)) {
766767
item = JSON.parse(json);
767768
}
768769
} else {
769-
await backupStore.set(filename, JSON.stringify(item));
770+
await this.backupStore.set(filename, JSON.stringify(item));
770771
}
771772
return item;
772773
}
773774
public async _saveSessions(sessions: any[]): Promise<void> {
774775
try {
775776
const filename: string = Config.nodered_id + "_sessions";
776-
await backupStore.set(filename, JSON.stringify(sessions));
777+
await this.backupStore.set(filename, JSON.stringify(sessions));
777778
if (WebSocketClient.instance.isConnected()) {
778779
this.last_reload = new Date();
779780
var result = await NoderedUtil.Query("nodered", { _type: "session", nodered_id: Config.nodered_id }, null, null, 1, 0, null);

OpenFlowNodeRED/src/nodered/nodes/api_nodes.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { Logger } from "../../Logger";
66
import { NoderedUtil, SigninMessage, TokenUser, Message, WebSocketClient, Base, mapFunc, reduceFunc, finalizeFunc, UpdateOneMessage } from "openflow-api";
77
import * as path from "path";
88
import { FileSystemCache } from "openflow-api";
9-
const backupStore = new FileSystemCache(path.join(Config.logpath, '.cache'));
109

1110
export interface Iapi_credentials {
1211
}

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.1.22
1+
1.1.23

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openiap",
3-
"version": "1.1.22",
3+
"version": "1.1.23",
44
"description": "Simple wrapper around NodeRed, RabbitMQ and MongoDB to support a more scaleable NodeRed implementation.\r Also the \"backend\" for [OpenRPA](https://github.com/skadefro/OpenRPA)",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)