1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Avoid unnecessary re-reading of file context when caching is enabled

This commit is contained in:
Nick O'Leary 2018-07-03 11:29:45 +01:00
parent 7d702e8332
commit a1251371d7
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
2 changed files with 9 additions and 2 deletions

View File

@ -192,8 +192,10 @@ LocalFileSystem.prototype._set = function(scope, key, value, callback) {
LocalFileSystem.prototype.set = function(scope, key, value, callback) {
if (this.cache) {
this.cache.set(scope,key,value,callback);
this._set(scope,key,value, function(err) {
// TODO: log any errors
// With cache enabled, no need to re-read the file prior to writing.
var newContext = this.cache._export()[scope];
var storagePath = getStoragePath(this.storageBaseDir ,scope);
fs.outputFile(storagePath + ".json", JSON.stringify(newContext, undefined, 4), "utf8").catch(function(err) {
});
} else {
this._set(scope,key,value,callback);

View File

@ -109,6 +109,11 @@ Memory.prototype.clean = function(activeNodes){
return Promise.resolve();
}
Memory.prototype._export = function() {
return this.data;
}
module.exports = function(config){
return new Memory(config);
};