Comparing version 7.0.4 to 7.0.5
@@ -7,2 +7,5 @@ # Change Log | ||
## [7.0.5] - 2018-03-06 | ||
- **Improved** `all` method, now can return also a plain object | ||
## [7.0.4] - 2018-02-28 | ||
@@ -9,0 +12,0 @@ - **Improved** `save` method, now create the full path if not exists |
{ | ||
"name": "incache", | ||
"version": "7.0.4", | ||
"version": "7.0.5", | ||
"description": "Powerful key/value in-memory storage or on disk to persist some data", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -351,47 +351,47 @@ const helper = require('./helper'); | ||
//if (helper.isServer()) { | ||
if (opts.autoLoad) | ||
this.load().then().catch((e) => { | ||
}); | ||
if (opts.autoLoad) | ||
this.load().then().catch((e) => { | ||
}); | ||
/* istanbul ignore else */ | ||
if (opts.autoSave || opts.save) { | ||
/* istanbul ignore else */ | ||
if (opts.autoSave || opts.save) { | ||
if (opts.autoSaveMode === SAVE_MODE.TERMINATE && helper.isServer()) { | ||
let self = this; | ||
/* istanbul ignore else */ | ||
if (opts.autoSaveMode === SAVE_MODE.TERMINATE && helper.isServer()) { | ||
let self = this; | ||
// Wrap function | ||
function pWrite() { | ||
self.save().then().catch((e) => { | ||
}); | ||
} | ||
// Wrap function | ||
function pWrite() { | ||
self.save().then().catch((e) => { | ||
}); | ||
} | ||
// Remove if event already exists | ||
process.removeListener('exit', pWrite); | ||
process.removeListener('SIGINT', pWrite); | ||
// Remove if event already exists | ||
process.removeListener('exit', pWrite); | ||
process.removeListener('SIGINT', pWrite); | ||
//process.stdin.resume(); | ||
process.on('exit', pWrite); | ||
process.on('SIGINT', pWrite); | ||
//process.stdin.resume(); | ||
process.on('exit', pWrite); | ||
process.on('SIGINT', pWrite); | ||
} else if (opts.autoSaveMode === SAVE_MODE.TIMER) { | ||
/* istanbul ignore else */ | ||
if (this._timerSaveCheck) { | ||
clearInterval(this._timerSaveCheck); | ||
this._timerSaveCheck = null; | ||
} | ||
} else if (opts.autoSaveMode === SAVE_MODE.TIMER) { | ||
/* istanbul ignore else */ | ||
if (this._timerSaveCheck) { | ||
clearInterval(this._timerSaveCheck); | ||
this._timerSaveCheck = null; | ||
} | ||
/* istanbul ignore else */ | ||
if (opts.autoSavePeriod) { | ||
this._timerSaveCheck = setInterval(() => { | ||
if (this._lastChange !== this._lastChangeDetected) { | ||
this._lastChangeDetected = this._lastChange; | ||
this.save().then().catch(e => { | ||
}); | ||
} | ||
}, opts.autoSavePeriod * 1000); | ||
} | ||
/* istanbul ignore else */ | ||
if (opts.autoSavePeriod) { | ||
this._timerSaveCheck = setInterval(() => { | ||
if (this._lastChange !== this._lastChangeDetected) { | ||
this._lastChangeDetected = this._lastChange; | ||
this.save().then().catch(e => { | ||
}); | ||
} | ||
}, opts.autoSavePeriod * 1000); | ||
} | ||
} | ||
} | ||
} | ||
//} | ||
@@ -834,6 +834,7 @@ | ||
* Fetch all records | ||
* @returns {Array} | ||
* @param asObject | ||
* @returns {*} | ||
*/ | ||
all() { | ||
let records = []; | ||
all(asObject = false) { | ||
let records = asObject ? {} : []; | ||
@@ -845,6 +846,10 @@ for (let key in this._memory.data) { | ||
} else { | ||
records.push({ | ||
key: key, | ||
value: this._memory.data[key].value | ||
}); | ||
if (Array.isArray(records)) { | ||
records.push({ | ||
key: key, | ||
value: this._memory.data[key].value | ||
}); | ||
} else { | ||
records[key] = this._memory.data[key].value; | ||
} | ||
} | ||
@@ -851,0 +856,0 @@ } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
339109
7112