@aofl/cache-manager
Advanced tools
Comparing version 3.12.1 to 3.13.0
@@ -1,2 +0,2 @@ | ||
module.exports=function(e){var t={};function r(n){if(t[n])return t[n].exports;var s=t[n]={i:n,l:!1,exports:{}};return e[n].call(s.exports,s,s.exports,r),s.l=!0,s.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)r.d(n,s,function(t){return e[t]}.bind(null,s));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="/",r(r.s="QfWi")}({"8vQp":function(e,t){e.exports=require("@babel/runtime/helpers/defineProperty")},MmcY:function(e,t){e.exports=require("@babel/runtime/helpers/classCallCheck")},QfWi:function(e,t,r){"use strict";r.r(t),r.d(t,"CacheManager",(function(){return d})),r.d(t,"cacheTypeEnumerate",(function(){return c})),r.d(t,"MemoryStorage",(function(){return h}));var n,s=r("MmcY"),i=r.n(s),o=r("iTvO"),a=r.n(o),u=r("8vQp"),l=r.n(u),c={MEMORY:0,LOCAL:1,SESSION:2},h=function(){function e(){i()(this,e)}return a()(e,null,[{key:"clear",value:function(){for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&e.removeItem(t)}},{key:"getItem",value:function(t){return Object.prototype.hasOwnProperty.call(e,t)?e[t]:null}},{key:"setItem",value:function(t,r){e[t]=r}},{key:"removeItem",value:function(t){e[t]=null,delete e[t]}},{key:"size",get:function(){var t=0;for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t++;return t}}]),e}(),y=r("rlan"),p=r.n(y),f=(n={},l()(n,c.LOCAL,localStorage),l()(n,c.SESSION,sessionStorage),l()(n,c.MEMORY,h),n),v=Symbol("expire"),d=function(){function e(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:c.MEMORY,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:36e5;i()(this,e),this.storage=f[r],this.storageType=r,this.namespace=t,this.storedKeys=this.getStoredKeys(),this.expire=n}return a()(e,[{key:"getStoredKeys",value:function(){var e=[];for(var t in this.storage)Object.hasOwnProperty.call(this.storage,t)&&0===t.indexOf(this.namespace+"_")&&e.push(t);return e}},{key:"getNamespaceKey",value:function(e){return this.storedKeys.indexOf(e)>-1?e:this.namespace+"_"+p()(e)}},{key:"setItem",value:function(e,t){var r={t:Date.now(),v:t};this.storageType!==c.LOCAL&&this.storageType!==c.SESSION||(r=JSON.stringify(r));var n=this.getNamespaceKey(e);this.storage.setItem(n,r),this.storedKeys.push(n)}},{key:"getItem",value:function(e){var t=this.storage.getItem(this.getNamespaceKey(e));return this.storageType!==c.LOCAL&&this.storageType!==c.SESSION||(t=JSON.parse(t)),null!==t&&Object.hasOwnProperty.call(t,"t")?this.isExpired(e)?(this.removeItem(e),null):t.v:t}},{key:"getCollection",value:function(){var e={};this.storedKeys=this.getStoredKeys();for(var t=0;t<this.storedKeys.length;t++)this.isExpired(this.storedKeys[t])||(e[this.storedKeys[t]]=this.getItem(this.storedKeys[t]));return e}},{key:"removeItem",value:function(e){var t=this.getNamespaceKey(e),r=this.storedKeys.indexOf(t);r>-1&&(this.storage.removeItem(t),this.storedKeys.splice(r,1))}},{key:"clear",value:function(){for(var e=0;e<this.storedKeys.length;e++)this.storage.removeItem(this.storedKeys[e]);this.storedKeys=[]}},{key:"isExpired",value:function(e){if("number"!=typeof this.expire||this.expire<=0)return!1;var t=this.getNamespaceKey(e),r=this.storage.getItem(t);if(this.storageType===c.LOCAL||this.storageType===c.SESSION)try{r=JSON.parse(r)}catch(e){}return null===r||r.t<Date.now()-this.expire}},{key:"removeExpired",value:function(){for(var e=0;e<this.storedKeys.length;e++)this.isExpired(this.storedKeys[e])&&this.removeItem(this.storedKeys[e])}},{key:"destruct",value:function(){clearInterval(this.interval),this.namespace=null,this.storage=null,this.storageType=null,this.expire=null,this.storedKeys=null,this.interval=null}},{key:"expire",get:function(){return this[v]},set:function(e){var t=this;this[v]=e,null!==this.interval&&clearInterval(this.interval),e>0&&e<2147483647&&(this.interval=setInterval((function(){return t.removeExpired()}),e))}},{key:"size",get:function(){var e=this.getCollection();return Object.keys(e).length}}]),e}()},iTvO:function(e,t){e.exports=require("@babel/runtime/helpers/createClass")},rlan:function(e,t){e.exports=require("tiny-js-md5")}}); | ||
module.exports=function(e){var t={};function r(n){if(t[n])return t[n].exports;var s=t[n]={i:n,l:!1,exports:{}};return e[n].call(s.exports,s,s.exports,r),s.l=!0,s.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)r.d(n,s,function(t){return e[t]}.bind(null,s));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="/",r(r.s="QfWi")}({"8vQp":function(e,t){e.exports=require("@babel/runtime/helpers/defineProperty")},MmcY:function(e,t){e.exports=require("@babel/runtime/helpers/classCallCheck")},QfWi:function(e,t,r){"use strict";r.r(t),r.d(t,"CacheManager",(function(){return d})),r.d(t,"cacheTypeEnumerate",(function(){return c})),r.d(t,"MemoryStorage",(function(){return h}));var n,s=r("MmcY"),i=r.n(s),o=r("iTvO"),a=r.n(o),u=r("8vQp"),l=r.n(u),c={MEMORY:0,LOCAL:1,SESSION:2},h=function(){function e(){i()(this,e)}return a()(e,null,[{key:"clear",value:function(){for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&e.removeItem(t)}},{key:"size",get:function(){var t=0;for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t++;return t}},{key:"getItem",value:function(t){return Object.prototype.hasOwnProperty.call(e,t)?e[t]:null}},{key:"setItem",value:function(t,r){e[t]=r}},{key:"removeItem",value:function(t){e[t]=null,delete e[t]}}]),e}(),y=r("rlan"),p=r.n(y),f=(n={},l()(n,c.LOCAL,localStorage),l()(n,c.SESSION,sessionStorage),l()(n,c.MEMORY,h),n),v=Symbol("expire"),d=function(){function e(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:c.MEMORY,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:36e5;i()(this,e),this.storage=f[r],this.storageType=r,this.namespace=t,this.storedKeys=this.getStoredKeys(),this.expire=n}return a()(e,[{key:"expire",get:function(){return this[v]},set:function(e){var t=this;this[v]=e,null!==this.interval&&clearInterval(this.interval),e>0&&e<2147483647&&(this.interval=setInterval((function(){return t.removeExpired()}),e))}},{key:"size",get:function(){var e=this.getCollection();return Object.keys(e).length}},{key:"getStoredKeys",value:function(){var e=[];for(var t in this.storage)Object.hasOwnProperty.call(this.storage,t)&&0===t.indexOf(this.namespace+"_")&&e.push(t);return e}},{key:"getNamespaceKey",value:function(e){return this.storedKeys.indexOf(e)>-1?e:this.namespace+"_"+p()(e)}},{key:"setItem",value:function(e,t){var r={t:Date.now(),v:t};this.storageType!==c.LOCAL&&this.storageType!==c.SESSION||(r=JSON.stringify(r));var n=this.getNamespaceKey(e);this.storage.setItem(n,r),this.storedKeys.push(n)}},{key:"getItem",value:function(e){var t=this.storage.getItem(this.getNamespaceKey(e));return this.storageType!==c.LOCAL&&this.storageType!==c.SESSION||(t=JSON.parse(t)),null!==t&&Object.hasOwnProperty.call(t,"t")?this.isExpired(e)?(this.removeItem(e),null):t.v:t}},{key:"getCollection",value:function(){var e={};this.storedKeys=this.getStoredKeys();for(var t=0;t<this.storedKeys.length;t++)this.isExpired(this.storedKeys[t])||(e[this.storedKeys[t]]=this.getItem(this.storedKeys[t]));return e}},{key:"removeItem",value:function(e){var t=this.getNamespaceKey(e),r=this.storedKeys.indexOf(t);r>-1&&(this.storage.removeItem(t),this.storedKeys.splice(r,1))}},{key:"clear",value:function(){for(var e=0;e<this.storedKeys.length;e++)this.storage.removeItem(this.storedKeys[e]);this.storedKeys=[]}},{key:"isExpired",value:function(e){if("number"!=typeof this.expire||this.expire<=0)return!1;var t=this.getNamespaceKey(e),r=this.storage.getItem(t);if(this.storageType===c.LOCAL||this.storageType===c.SESSION)try{r=JSON.parse(r)}catch(e){}return null===r||r.t<Date.now()-this.expire}},{key:"removeExpired",value:function(){for(var e=0;e<this.storedKeys.length;e++)this.isExpired(this.storedKeys[e])&&this.removeItem(this.storedKeys[e])}},{key:"destruct",value:function(){clearInterval(this.interval),this.namespace=null,this.storage=null,this.storageType=null,this.expire=null,this.storedKeys=null,this.interval=null}}]),e}()},iTvO:function(e,t){e.exports=require("@babel/runtime/helpers/createClass")},rlan:function(e,t){e.exports=require("tiny-js-md5")}}); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@aofl/cache-manager", | ||
"version": "3.12.1", | ||
"version": "3.13.0", | ||
"description": "Provides a unified class for storing objects in Storage-like Objects", | ||
@@ -35,3 +35,3 @@ "main": "index.js", | ||
"devDependencies": { | ||
"@aofl/cli": "^3.12.1", | ||
"@aofl/cli": "^3.13.0", | ||
"cross-env": "^6.0.3", | ||
@@ -38,0 +38,0 @@ "jsdoc": "^3.6.3", |
/** | ||
* Exports CacheManager, cacheTypeEnumerate, and MemoryStorage | ||
* | ||
* @module @aofl/cache-manager | ||
* @version 3.0.0 | ||
* @since 1.0.0 | ||
* @author Arian Khosravi <arian.khosravi@aofl.com> | ||
*/ | ||
@@ -12,16 +7,10 @@ declare module "@aofl/cache-manager" { | ||
* Creates an instance of CacheManager. | ||
* @param {*} namespace used to group keys controlled by each instance since the starage objects are shared | ||
* @param {*} [storageType=cacheTypeEnumerate.MEMORY] memory, local or session | ||
* @param {number} [expire=3600000] cache expiration in ms | ||
* @param namespace - used to group keys controlled by each instance since the starage objects are shared | ||
* @param [storageType = cacheTypeEnumerate.MEMORY] - memory, local or session | ||
* @param [expire = 3600000] - cache expiration in ms | ||
*/ | ||
class CacheManager { | ||
constructor(namespace: any, storageType?: any, expire?: number); | ||
/** @type {cacheTypeEnumerate} | ||
*/ | ||
storageType: cacheTypeEnumerate; | ||
/** @type {String} | ||
*/ | ||
namespace: string; | ||
/** @type {Number} | ||
*/ | ||
expire: number; | ||
@@ -31,5 +20,2 @@ /** | ||
* number of data items stored in the Storage object. | ||
* | ||
* @readonly | ||
* @type {Number} | ||
*/ | ||
@@ -39,4 +25,2 @@ readonly size: number; | ||
* Returns keys controlled by the instance of CacheManager | ||
* | ||
* @return {Array} | ||
*/ | ||
@@ -46,5 +30,2 @@ getStoredKeys(): any[]; | ||
* Returns the serialized key based on namespace | ||
* | ||
* @param {String} key | ||
* @return {String} | ||
*/ | ||
@@ -55,5 +36,4 @@ getNamespaceKey(key: string): string; | ||
* that key to the storage, or update that key's value if it already exists | ||
* | ||
* @param {String} key A String containing the name of the key you want to create/update. | ||
* @param {*} value The value you want to give the key you are creating/updating. | ||
* @param key - A String containing the name of the key you want to create/update. | ||
* @param value - The value you want to give the key you are creating/updating. | ||
*/ | ||
@@ -64,5 +44,3 @@ setItem(key: string, value: any): void; | ||
* key's value or null if the key does not exist. | ||
* | ||
* @param {String} key The name of the key you want to retrieve the value of | ||
* @return {*} | ||
* @param key - The name of the key you want to retrieve the value of | ||
*/ | ||
@@ -73,4 +51,2 @@ getItem(key: string): any; | ||
* pairs that that instance of CacheManager tracks. | ||
* | ||
* @return {Object} | ||
*/ | ||
@@ -82,4 +58,3 @@ getCollection(): any; | ||
* method will do nothing. | ||
* | ||
* @param {String} key The name of the key you want to remove | ||
* @param key - The name of the key you want to remove | ||
*/ | ||
@@ -94,5 +69,3 @@ removeItem(key: string): void; | ||
* is expired. | ||
* | ||
* @param {String} key The name of the key you want to check if is expired. | ||
* @return {Boolean} | ||
* @param key - The name of the key you want to check if is expired. | ||
*/ | ||
@@ -113,18 +86,17 @@ isExpired(key: string): boolean; | ||
* Cache types enumerate | ||
* | ||
* @memberof module:@aofl/cache-manager | ||
* @readonly | ||
* @static | ||
* @enum {Number} | ||
*/ | ||
const enum cacheTypeEnumerate { | ||
/** | ||
* memoryStorage | ||
*/ | ||
MEMORY = 0, | ||
/** | ||
* localStorage | ||
*/ | ||
LOCAL = 1, | ||
/** | ||
* sessionStorage | ||
*/ | ||
SESSION = 2 | ||
} | ||
/** | ||
* | ||
* | ||
* @memberof module:@aofl/cache-manager | ||
*/ | ||
class MemoryStorage { | ||
@@ -138,5 +110,2 @@ /** | ||
* number of data items stored in the Storage object. | ||
* | ||
* @readonly | ||
* @type {Number} | ||
*/ | ||
@@ -147,5 +116,3 @@ static readonly size: number; | ||
* value or null if the key does not exist. | ||
* | ||
* @param {String} key The name of the key you want to retrieve the value of. | ||
* @return {*} | ||
* @param key - The name of the key you want to retrieve the value of. | ||
*/ | ||
@@ -156,5 +123,4 @@ static getItem(key: string): any; | ||
* that key to the storage, or update that key's value if it already exists. | ||
* | ||
* @param {*} key The name of the key you want to create/update. | ||
* @param {*} value The value you want to give the key you are creating/updating. | ||
* @param key - The name of the key you want to create/update. | ||
* @param value - The value you want to give the key you are creating/updating. | ||
*/ | ||
@@ -166,4 +132,3 @@ static setItem(key: any, value: any): void; | ||
* will do nothing. | ||
* | ||
* @param {String} key The name of the key you want to remove. | ||
* @param key - The name of the key you want to remove. | ||
*/ | ||
@@ -170,0 +135,0 @@ static removeItem(key: string): void; |
Sorry, the diff of this file is not supported yet
40219
483