im having node JS application and I build some module which is responsible to parse data and provide access to its property,Now I need to access to this parser from different module but I want that If I access in the first time and I sent the data ,in second time and after don't parse the data again since it already parsed...I try to save the object in some cache which doesn't work(when I access from different(for example in second time) module the cacheObj is empty,what am I doing wrong here?
"use strict";
var Parser = require('myParser'),
_ = require('lodash');
function myParser(data) {
if (!(this instanceof myParser)) return new myParser(data);
if (!_.isEmpty(this.cacheObj)) {
this.parsedData = this.cacheObj;
} else {
this.parsedData = Parser.parse(data);
this.cacheObj = this.parsedData;
}
}
myParser.prototype = {
cacheObj: {},
getPropOne: function () {
return this.parsedData.propOne;
},
getPropTwo: function () {
return this.parsedData.propTwo;
}
};
module.exports = myParser;
In short Lets say that I need to parse the data and I want to share this parsed properties in different modules.the first module which call to this is responsible to pass the data and other modules doesn't need to send the data since I already store the parsedData.
Aucun commentaire:
Enregistrer un commentaire