Comparing version 0.4.3 to 0.5.0
@@ -7,2 +7,6 @@ # Changelog | ||
## [0.5.0] - 2018-06-25 | ||
### Changed | ||
- expire time support params pass in | ||
## [0.4.3] - 2018-06-21 | ||
@@ -9,0 +13,0 @@ ### Changed |
@@ -477,15 +477,15 @@ "use strict" | ||
case 2:return r=n.sent(),[2,Promise.reject(r)] | ||
case 3:return[2]}})})},e.prototype.isExpired=function(e){return n(this,void 0,void 0,function(){var t,r | ||
return o(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.getMeta(e)] | ||
case 1:return(t=n.sent())&&t.expire?[2,Promise.resolve(this.expiredVaule(t.expire))]:[2,Promise.resolve(!1)] | ||
case 2:return r=n.sent(),[2,Promise.reject(r)] | ||
case 3:return[2]}})})},e.prototype.get=function(e){return n(this,void 0,void 0,function(){var t,r,n | ||
case 3:return[2]}})})},e.prototype.isExpired=function(e,t){return void 0===t&&(t=(new Date).getTime()),n(this,void 0,void 0,function(){var r,n | ||
return o(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,this.getMeta(e)] | ||
case 1:return(r=o.sent())&&r.expire?[2,Promise.resolve(this.expiredVaule(r.expire,t))]:[2,Promise.resolve(!1)] | ||
case 2:return n=o.sent(),[2,Promise.reject(n)] | ||
case 3:return[2]}})})},e.prototype.get=function(e,t){return void 0===t&&(t=(new Date).getTime()),n(this,void 0,void 0,function(){var r,n,i | ||
return o(this,function(o){switch(o.label){case 0:return o.trys.push([0,7,,8]),[4,this.getMeta(e)] | ||
case 1:return(t=o.sent())?void 0===t.length||void 0===t.expire||void 0===t.now||void 0===t.count?[3,6]:this.expiredVaule(t.expire)?[4,this.remove(e)]:[3,3]:[2,Promise.resolve(null)] | ||
case 1:return(r=o.sent())?void 0===r.length||void 0===r.expire||void 0===r.now||void 0===r.count?[3,6]:this.expiredVaule(r.expire,t)?[4,this.remove(e)]:[3,3]:[2,Promise.resolve(null)] | ||
case 2:return o.sent(),[2,Promise.resolve(null)] | ||
case 3:return[4,this.valueCacheInstance.get(e)] | ||
case 4:return r=o.sent(),[4,this.setMeta(e)] | ||
case 5:return o.sent(),[2,Promise.resolve(r)] | ||
case 6:return[2,Promise.resolve(t)] | ||
case 7:return n=o.sent(),[2,Promise.reject(n)] | ||
case 4:return n=o.sent(),[4,this.setMeta(e)] | ||
case 5:return o.sent(),[2,Promise.resolve(n)] | ||
case 6:return[2,Promise.resolve(r)] | ||
case 7:return i=o.sent(),[2,Promise.reject(i)] | ||
case 8:return[2]}})})},e.prototype.gets=function(e){return n(this,void 0,void 0,function(){var t,r,n,i,a,s | ||
@@ -546,4 +546,3 @@ return o(this,function(o){switch(o.label){case 0:o.trys.push([0,5,,6]),t=[],r=0,n=e,o.label=1 | ||
case 6:return m=o.sent(),[2,Promise.reject(m)] | ||
case 7:return[2]}})})},e.prototype.expiredVaule=function(e){var t=(new Date).getTime() | ||
return e&&e>0&&e<t},e.prototype.setMeta=function(e,t,i){return void 0===t&&(t=""),void 0===i&&(i=-1),n(this,void 0,void 0,function(){var n,a,s,u,c,f,l | ||
case 7:return[2]}})})},e.prototype.expiredVaule=function(e,t){return e&&e>0&&e<t},e.prototype.setMeta=function(e,t,i){return void 0===t&&(t=""),void 0===i&&(i=-1),n(this,void 0,void 0,function(){var n,a,s,u,c,f,l | ||
return o(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,this.getMeta(e)] | ||
@@ -550,0 +549,0 @@ case 1:return n=o.sent(),a=(new Date).getTime(),s=void 0,s=utils.isDate(i)?i.getTime():utils.isNumber(i)&&i>0?a+1e3*i:-1,u=0,n&&void 0!==n.count&&(u=n.count+1),c=void 0,c=t?{length:utils.utf16ByteLength(JSON.stringify(t)),now:a,count:u,expire:s}:r({},n,{now:a,count:u}),f=this.cacheConfig.isCompress?LZString_1.default.compressToUTF16(JSON.stringify(c)):JSON.stringify(c),[2,this.metaCacheInstance.set(e,f)] |
@@ -475,15 +475,15 @@ var commonjsGlobal="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{} | ||
case 2:return r=n.sent(),[2,Promise.reject(r)] | ||
case 3:return[2]}})})},e.prototype.isExpired=function(e){return n(this,void 0,void 0,function(){var t,r | ||
return o(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.getMeta(e)] | ||
case 1:return(t=n.sent())&&t.expire?[2,Promise.resolve(this.expiredVaule(t.expire))]:[2,Promise.resolve(!1)] | ||
case 2:return r=n.sent(),[2,Promise.reject(r)] | ||
case 3:return[2]}})})},e.prototype.get=function(e){return n(this,void 0,void 0,function(){var t,r,n | ||
case 3:return[2]}})})},e.prototype.isExpired=function(e,t){return void 0===t&&(t=(new Date).getTime()),n(this,void 0,void 0,function(){var r,n | ||
return o(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,this.getMeta(e)] | ||
case 1:return(r=o.sent())&&r.expire?[2,Promise.resolve(this.expiredVaule(r.expire,t))]:[2,Promise.resolve(!1)] | ||
case 2:return n=o.sent(),[2,Promise.reject(n)] | ||
case 3:return[2]}})})},e.prototype.get=function(e,t){return void 0===t&&(t=(new Date).getTime()),n(this,void 0,void 0,function(){var r,n,i | ||
return o(this,function(o){switch(o.label){case 0:return o.trys.push([0,7,,8]),[4,this.getMeta(e)] | ||
case 1:return(t=o.sent())?void 0===t.length||void 0===t.expire||void 0===t.now||void 0===t.count?[3,6]:this.expiredVaule(t.expire)?[4,this.remove(e)]:[3,3]:[2,Promise.resolve(null)] | ||
case 1:return(r=o.sent())?void 0===r.length||void 0===r.expire||void 0===r.now||void 0===r.count?[3,6]:this.expiredVaule(r.expire,t)?[4,this.remove(e)]:[3,3]:[2,Promise.resolve(null)] | ||
case 2:return o.sent(),[2,Promise.resolve(null)] | ||
case 3:return[4,this.valueCacheInstance.get(e)] | ||
case 4:return r=o.sent(),[4,this.setMeta(e)] | ||
case 5:return o.sent(),[2,Promise.resolve(r)] | ||
case 6:return[2,Promise.resolve(t)] | ||
case 7:return n=o.sent(),[2,Promise.reject(n)] | ||
case 4:return n=o.sent(),[4,this.setMeta(e)] | ||
case 5:return o.sent(),[2,Promise.resolve(n)] | ||
case 6:return[2,Promise.resolve(r)] | ||
case 7:return i=o.sent(),[2,Promise.reject(i)] | ||
case 8:return[2]}})})},e.prototype.gets=function(e){return n(this,void 0,void 0,function(){var t,r,n,i,a,s | ||
@@ -544,4 +544,3 @@ return o(this,function(o){switch(o.label){case 0:o.trys.push([0,5,,6]),t=[],r=0,n=e,o.label=1 | ||
case 6:return m=o.sent(),[2,Promise.reject(m)] | ||
case 7:return[2]}})})},e.prototype.expiredVaule=function(e){var t=(new Date).getTime() | ||
return e&&e>0&&e<t},e.prototype.setMeta=function(e,t,i){return void 0===t&&(t=""),void 0===i&&(i=-1),n(this,void 0,void 0,function(){var n,a,s,u,c,f,l | ||
case 7:return[2]}})})},e.prototype.expiredVaule=function(e,t){return e&&e>0&&e<t},e.prototype.setMeta=function(e,t,i){return void 0===t&&(t=""),void 0===i&&(i=-1),n(this,void 0,void 0,function(){var n,a,s,u,c,f,l | ||
return o(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,this.getMeta(e)] | ||
@@ -548,0 +547,0 @@ case 1:return n=o.sent(),a=(new Date).getTime(),s=void 0,s=utils.isDate(i)?i.getTime():utils.isNumber(i)&&i>0?a+1e3*i:-1,u=0,n&&void 0!==n.count&&(u=n.count+1),c=void 0,c=t?{length:utils.utf16ByteLength(JSON.stringify(t)),now:a,count:u,expire:s}:r({},n,{now:a,count:u}),f=this.cacheConfig.isCompress?LZString_1.default.compressToUTF16(JSON.stringify(c)):JSON.stringify(c),[2,this.metaCacheInstance.set(e,f)] |
@@ -476,15 +476,15 @@ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.Mycache={})}(this,function(e){"use strict" | ||
case 2:return r=n.sent(),[2,Promise.reject(r)] | ||
case 3:return[2]}})})},e.prototype.isExpired=function(e){return o(this,void 0,void 0,function(){var t,r | ||
return a(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.getMeta(e)] | ||
case 1:return(t=n.sent())&&t.expire?[2,Promise.resolve(this.expiredVaule(t.expire))]:[2,Promise.resolve(!1)] | ||
case 2:return r=n.sent(),[2,Promise.reject(r)] | ||
case 3:return[2]}})})},e.prototype.get=function(e){return o(this,void 0,void 0,function(){var t,r,n | ||
return a(this,function(o){switch(o.label){case 0:return o.trys.push([0,7,,8]),[4,this.getMeta(e)] | ||
case 1:return(t=o.sent())?void 0===t.length||void 0===t.expire||void 0===t.now||void 0===t.count?[3,6]:this.expiredVaule(t.expire)?[4,this.remove(e)]:[3,3]:[2,Promise.resolve(null)] | ||
case 2:return o.sent(),[2,Promise.resolve(null)] | ||
case 3:return[2]}})})},e.prototype.isExpired=function(e,t){return void 0===t&&(t=(new Date).getTime()),o(this,void 0,void 0,function(){var r,n | ||
return a(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,this.getMeta(e)] | ||
case 1:return(r=o.sent())&&r.expire?[2,Promise.resolve(this.expiredVaule(r.expire,t))]:[2,Promise.resolve(!1)] | ||
case 2:return n=o.sent(),[2,Promise.reject(n)] | ||
case 3:return[2]}})})},e.prototype.get=function(e,t){return void 0===t&&(t=(new Date).getTime()),o(this,void 0,void 0,function(){var r,n,o | ||
return a(this,function(i){switch(i.label){case 0:return i.trys.push([0,7,,8]),[4,this.getMeta(e)] | ||
case 1:return(r=i.sent())?void 0===r.length||void 0===r.expire||void 0===r.now||void 0===r.count?[3,6]:this.expiredVaule(r.expire,t)?[4,this.remove(e)]:[3,3]:[2,Promise.resolve(null)] | ||
case 2:return i.sent(),[2,Promise.resolve(null)] | ||
case 3:return[4,this.valueCacheInstance.get(e)] | ||
case 4:return r=o.sent(),[4,this.setMeta(e)] | ||
case 5:return o.sent(),[2,Promise.resolve(r)] | ||
case 6:return[2,Promise.resolve(t)] | ||
case 7:return n=o.sent(),[2,Promise.reject(n)] | ||
case 4:return n=i.sent(),[4,this.setMeta(e)] | ||
case 5:return i.sent(),[2,Promise.resolve(n)] | ||
case 6:return[2,Promise.resolve(r)] | ||
case 7:return o=i.sent(),[2,Promise.reject(o)] | ||
case 8:return[2]}})})},e.prototype.gets=function(e){return o(this,void 0,void 0,function(){var t,r,n,o,i,c | ||
@@ -545,4 +545,3 @@ return a(this,function(a){switch(a.label){case 0:a.trys.push([0,5,,6]),t=[],r=0,n=e,a.label=1 | ||
case 6:return m=a.sent(),[2,Promise.reject(m)] | ||
case 7:return[2]}})})},e.prototype.expiredVaule=function(e){var t=(new Date).getTime() | ||
return e&&e>0&&e<t},e.prototype.setMeta=function(e,t,r){return void 0===t&&(t=""),void 0===r&&(r=-1),o(this,void 0,void 0,function(){var o,s,u,f,l,h,d | ||
case 7:return[2]}})})},e.prototype.expiredVaule=function(e,t){return e&&e>0&&e<t},e.prototype.setMeta=function(e,t,r){return void 0===t&&(t=""),void 0===r&&(r=-1),o(this,void 0,void 0,function(){var o,s,u,f,l,h,d | ||
return a(this,function(a){switch(a.label){case 0:return a.trys.push([0,2,,3]),[4,this.getMeta(e)] | ||
@@ -549,0 +548,0 @@ case 1:return o=a.sent(),s=(new Date).getTime(),u=void 0,u=i.isDate(r)?r.getTime():i.isNumber(r)&&r>0?s+1e3*r:-1,f=0,o&&void 0!==o.count&&(f=o.count+1),l=void 0,l=t?{length:i.utf16ByteLength(JSON.stringify(t)),now:s,count:f,expire:u}:n({},o,{now:s,count:f}),h=this.cacheConfig.isCompress?c.default.compressToUTF16(JSON.stringify(l)):JSON.stringify(l),[2,this.metaCacheInstance.set(e,h)] |
{ | ||
"name": "mycache", | ||
"version": "0.4.3", | ||
"version": "0.5.0", | ||
"description": "A Cache library", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -112,3 +112,3 @@ import * as typed from '../typed'; | ||
public async isExpired(key: string): Promise<boolean> { | ||
public async isExpired(key: string, currentTime: number = new Date().getTime()): Promise<boolean> { | ||
try { | ||
@@ -118,3 +118,3 @@ const res = await this.getMeta(key); | ||
if (res && res.expire) { | ||
return Promise.resolve(this.expiredVaule(res.expire)); | ||
return Promise.resolve(this.expiredVaule(res.expire, currentTime)); | ||
} else { | ||
@@ -128,3 +128,3 @@ return Promise.resolve(false); | ||
public async get(key: string): Promise<any> { | ||
public async get(key: string, currentTime: number = new Date().getTime()): Promise<any> { | ||
try { | ||
@@ -139,3 +139,3 @@ const res = await this.getMeta(key); | ||
res.count !== undefined) { | ||
const isExpired = this.expiredVaule(res.expire); | ||
const isExpired = this.expiredVaule(res.expire, currentTime); | ||
@@ -323,5 +323,4 @@ if (isExpired) { | ||
private expiredVaule(expire: number): boolean { | ||
const now = new Date().getTime(); | ||
return expire && expire > 0 && expire < now; | ||
private expiredVaule(expire: number, currentTime: number): boolean { | ||
return expire && expire > 0 && expire < currentTime; | ||
} | ||
@@ -328,0 +327,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
8
1053871
20
6724