Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

angular-cache

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-cache - npm Package Compare versions

Comparing version 4.1.0 to 4.2.0

7

CHANGELOG.md

@@ -0,4 +1,9 @@

##### 4.2.0 27 April 2015
###### Backwards compatible bug fixes
- #174 - Cache not being fully emptied if using localStorage and multiple web pages
##### 4.1.0 30 March 2015
###### Backwards compatible API fixes
###### Backwards compatible API changes
- #169 - Official support for ngResource

@@ -5,0 +10,0 @@

7

dist/angular-cache.js
/*!
* angular-cache
* @version 4.1.0 - Homepage <http://jmdobry.github.io/angular-cache/>
* @version 4.2.0 - Homepage <http://jmdobry.github.io/angular-cache/>
* @author Jason Dobry <jason.dobry@gmail.com>

@@ -96,3 +96,3 @@ * @copyright (c) 2013-2015 Jason Dobry

var keySet = {},
key;
key = undefined;
for (key in collection) {

@@ -205,3 +205,3 @@ if (collection.hasOwnProperty(key)) {

this.peek = function () {
return _this.heap[0];
return _this.heap.length ? _this.heap[0] : undefined;
};

@@ -661,2 +661,3 @@

}
$$promises = {};
},

@@ -663,0 +664,0 @@

/*!
* angular-cache
* @version 4.1.0 - Homepage <http://jmdobry.github.io/angular-cache/>
* @version 4.2.0 - Homepage <http://jmdobry.github.io/angular-cache/>
* @author Jason Dobry <jason.dobry@gmail.com>

@@ -11,3 +11,3 @@ * @copyright (c) 2013-2015 Jason Dobry <http://www.pseudobry.com>

!function(a,b){"object"==typeof exports&&"object"==typeof module?module.exports=b(require("angular")):"function"==typeof define&&define.amd?define(["angular"],b):"object"==typeof exports?exports.angularCacheModuleName=b(require("angular")):a.angularCacheModuleName=b(a.angular)}(this,function(a){return function(a){function b(d){if(c[d])return c[d].exports;var e=c[d]={exports:{},id:d,loaded:!1};return a[d].call(e.exports,e,e.exports,b),e.loaded=!0,e.exports}var c={};return b.m=a,b.c=c,b.p="",b(0)}([function(a,b,c){function d(a,b,c){for(var d=a[c],e=b(d);c>0;){var f=Math.floor((c+1)/2)-1,g=a[f];if(e>=b(g))break;a[f]=d,a[c]=g,c=f}}var e=function(a){return a&&a.__esModule?a["default"]:a},f=function(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")},g=e(c(1)),h=function(a){var b=[],c=void 0;for(c in a)a.hasOwnProperty(c)&&b.push(c);return b},i=function(a){return a&&"function"==typeof a.then},j=function(a){return g.isNumber(a)?a.toString():a},k=function(a){var b,c={};for(b in a)a.hasOwnProperty(b)&&(c[b]=b);return c},l=function(a,b,c){for(var d=a.length,e=a[c],f=b(e);;){var g=2*(c+1),h=g-1,i=null;if(d>h){var j=a[h],k=b(j);f>k&&(i=h)}if(d>g){var l=a[g],m=b(l);m<(null===i?f:b(a[h]))&&(i=g)}if(null===i)break;a[c]=a[i],a[i]=e,c=i}},m=function p(a,b){var c=this;if(f(this,p),a||(a=function(a){return a}),b||(b=function(a,b){return a===b}),"function"!=typeof a)throw new Error('BinaryHeap([weightFunc][, compareFunc]): "weightFunc" must be a function!');if("function"!=typeof b)throw new Error('BinaryHeap([weightFunc][, compareFunc]): "compareFunc" must be a function!');this.weightFunc=a,this.compareFunc=b,this.heap=[],this.push=function(a){c.heap.push(a),d(c.heap,c.weightFunc,c.heap.length-1)},this.peek=function(){return c.heap[0]},this.pop=function(){var a=c.heap[0],b=c.heap.pop();return c.heap.length>0&&(c.heap[0]=b,l(c.heap,c.weightFunc,0)),a},this.remove=function(a){for(var b=c.heap.length,e=0;b>e;e++)if(c.compareFunc(c.heap[e],a)){var f=c.heap[e],g=c.heap.pop();return e!==b-1&&(c.heap[e]=g,d(c.heap,c.weightFunc,e),l(c.heap,c.weightFunc,e)),f}return null},this.removeAll=function(){c.heap=[]},this.size=function(){return c.heap.length}},n=function q(){f(this,q),this.$get=function(){return m}},o=function r(){var a=this;f(this,r);var b=this.defaults={capacity:Number.MAX_VALUE,maxAge:Number.MAX_VALUE,deleteOnExpire:"none",onExpire:null,cacheFlushInterval:null,recycleFreq:1e3,storageMode:"memory",storageImpl:null,disabled:!1,storagePrefix:"angular-cache.caches.",storeOnResolve:!1,storeOnReject:!1};this.$get=["$q",function(c){function d(a,b){return f(a,b)}var e={},f=function(a,d){if(a in e)throw new Error(""+a+" already exists!");if(!g.isString(a))throw new Error("cacheId must be a string!");var f={},l={},n=null,o=new m(function(a){return a.expires},g.equals),p=new m(function(a){return a.accessed},g.equals),q=e[a]={$$id:a,destroy:function(){clearInterval(this.$$cacheFlushIntervalId),clearInterval(this.$$recycleFreqId),this.removeAll(),n&&(n().removeItem(""+this.$$prefix+".keys"),n().removeItem(this.$$prefix)),n=null,f=null,p=null,o=null,this.$$prefix=null,delete e[this.$$id]},disable:function(){this.$$disabled=!0},enable:function(){delete this.$$disabled},get:function(a,b){var c=this;if(g.isArray(a)){var d=function(){var d=a,e=[];return g.forEach(d,function(a){var d=c.get(a,b);null!==d&&void 0!==d&&e.push(d)}),{v:e}}();if("object"==typeof d)return d.v}else if(a=j(a),this.$$disabled)return;if(b=b||{},!g.isString(a))throw new Error("key must be a string!");if(b&&!g.isObject(b))throw new Error("options must be an object!");if(b.onExpire&&!g.isFunction(b.onExpire))throw new Error("options.onExpire must be a function!");var e=void 0;if(n){if(l[a])return l[a];var h=n().getItem(""+this.$$prefix+".data."+a);if(!h)return;e=g.fromJson(h)}else{if(!(a in f))return;e=f[a]}var i=e.value,k=(new Date).getTime();return n?(p.remove({key:a,accessed:e.accessed}),e.accessed=k,p.push({key:a,accessed:k})):(p.remove(e),e.accessed=k,p.push(e)),"passive"===this.$$deleteOnExpire&&"expires"in e&&e.expires<k?(this.remove(a),this.$$onExpire?this.$$onExpire.call(this,a,e.value,b.onExpire):b.onExpire&&b.onExpire.call(this,a,e.value),i=void 0):n&&n().setItem(""+this.$$prefix+".data."+a,JSON.stringify(e)),i},info:function(a){if(a){var b=void 0;if(n){var c=n().getItem(""+this.$$prefix+".data."+a);return c?(b=g.fromJson(c),{created:b.created,accessed:b.accessed,expires:b.expires,isExpired:(new Date).getTime()-b.created>this.$$maxAge}):void 0}return a in f?(b=f[a],{created:b.created,accessed:b.accessed,expires:b.expires,isExpired:(new Date).getTime()-b.created>this.$$maxAge}):void 0}return{id:this.$$id,capacity:this.$$capacity,maxAge:this.$$maxAge,deleteOnExpire:this.$$deleteOnExpire,onExpire:this.$$onExpire,cacheFlushInterval:this.$$cacheFlushInterval,recycleFreq:this.$$recycleFreq,storageMode:this.$$storageMode,storageImpl:n?n():void 0,disabled:!!this.$$disabled,size:p&&p.size()||0}},keys:function(){if(n){var a=n().getItem(""+this.$$prefix+".keys");return a?g.fromJson(a):[]}return h(f)},keySet:function(){if(n){var a=n().getItem(""+this.$$prefix+".keys"),b={};if(a)for(var c=g.fromJson(a),d=0;d<c.length;d++)b[c[d]]=c[d];return b}return k(f)},put:function(a,b,d){var e=this;d=d||{};var h="storeOnResolve"in d?!!d.storeOnResolve:this.$$storeOnResolve,k="storeOnReject"in d?!!d.storeOnReject:this.$$storeOnReject,m=function(b,d){return function(f){return b&&(delete l[a],g.isObject(f)&&"status"in f&&"data"in f?(f=[f.status,f.data,f.headers(),f.statusText],e.put(a,f)):e.put(a,f)),d?c.reject(f):f}};if(!this.$$disabled&&null!==b&&void 0!==b){if(a=j(a),!g.isString(a))throw new Error("key must be a string!");var q=(new Date).getTime(),r={key:a,value:i(b)?b.then(m(h,!1),m(k,!0)):b,created:q,accessed:q};if(r.expires=r.created+this.$$maxAge,n){if(i(r.value))return l[a]=r.value,l[a];var s=n().getItem(""+this.$$prefix+".keys"),t=s?g.fromJson(s):[],u=n().getItem(""+this.$$prefix+".data."+a);u&&this.remove(a),o.push({key:a,expires:r.expires}),p.push({key:a,accessed:r.accessed}),n().setItem(""+this.$$prefix+".data."+a,JSON.stringify(r));for(var v=!1,w=0;w<t.length;w++)if(t[w]===a){v=!0;break}v||t.push(a),n().setItem(""+this.$$prefix+".keys",JSON.stringify(t))}else f[a]&&this.remove(a),o.push(r),p.push(r),f[a]=r,delete l[a];return p.size()>this.$$capacity&&this.remove(p.peek().key),b}},remove:function(a){if(a+="",delete l[a],!n){var b=f[a]?f[a].value:void 0;return p.remove(f[a]),o.remove(f[a]),f[a]=null,delete f[a],b}var c=n().getItem(""+this.$$prefix+".data."+a);if(c){var d=g.fromJson(c);p.remove({key:a,accessed:d.accessed}),o.remove({key:a,expires:d.expires}),n().removeItem(""+this.$$prefix+".data."+a);var e=n().getItem(""+this.$$prefix+".keys"),h=e?g.fromJson(e):[],i=h.indexOf(a);return i>=0&&h.splice(i,1),n().setItem(""+this.$$prefix+".keys",JSON.stringify(h)),d.value}},removeAll:function(){if(n){p.removeAll(),o.removeAll();var a=n().getItem(""+this.$$prefix+".keys");if(a)for(var b=g.fromJson(a),c=0;c<b.length;c++)this.remove(b[c]);n().setItem(""+this.$$prefix+".keys",JSON.stringify([]))}else{p.removeAll(),o.removeAll();for(var d in f)f[d]=null;f={}}},removeExpired:function(){for(var a=(new Date).getTime(),b={},c=void 0,d=void 0;(d=o.peek())&&d.expires<=a;)b[d.key]=d.value?d.value:null,o.pop();if(n)for(c in b){var e=n().getItem(""+this.$$prefix+".data."+c);e&&(b[c]=g.fromJson(e).value,this.remove(c))}else for(c in b)this.remove(c);if(this.$$onExpire)for(c in b)this.$$onExpire.call(this,c,b[c]);return b},setCacheFlushInterval:function(a){if(null===a)delete this.$$cacheFlushInterval;else{if(!g.isNumber(a))throw new Error("cacheFlushInterval must be a number!");if(0>a)throw new Error("cacheFlushInterval must be greater than zero!");a!==this.$$cacheFlushInterval&&(this.$$cacheFlushInterval=a,clearInterval(this.$$cacheFlushIntervalId),function(a){a.$$cacheFlushIntervalId=setInterval(function(){a.removeAll()},a.$$cacheFlushInterval)}(this))}},setCapacity:function(a){if(null===a)delete this.$$capacity;else{if(!g.isNumber(a))throw new Error("capacity must be a number!");if(0>a)throw new Error("capacity must be greater than zero!");this.$$capacity=a}for(var b={};p.size()>this.$$capacity;)b[p.peek().key]=this.remove(p.peek().key);return b},setDeleteOnExpire:function(a,b){if(null===a)delete this.$$deleteOnExpire;else{if(!g.isString(a))throw new Error("deleteOnExpire must be a string!");if("none"!==a&&"passive"!==a&&"aggressive"!==a)throw new Error('deleteOnExpire must be "none", "passive" or "aggressive"!');this.$$deleteOnExpire=a}b!==!1&&this.setRecycleFreq(this.$$recycleFreq)},setMaxAge:function(a){if(null===a)this.$$maxAge=Number.MAX_VALUE;else{if(!g.isNumber(a))throw new Error("maxAge must be a number!");if(0>a)throw new Error("maxAge must be greater than zero!");this.$$maxAge=a}var b=void 0,c=void 0,d=void 0;if(o.removeAll(),n){var e=n().getItem(""+this.$$prefix+".keys");for(c=e?g.fromJson(e):[],b=0;b<c.length;b++){d=c[b];var i=n().getItem(""+this.$$prefix+".data."+d);if(i){var j=g.fromJson(i);j.expires=this.$$maxAge===Number.MAX_VALUE?Number.MAX_VALUE:j.created+this.$$maxAge,o.push({key:d,expires:j.expires})}}}else for(c=h(f),b=0;b<c.length;b++)d=c[b],f[d].expires=this.$$maxAge===Number.MAX_VALUE?Number.MAX_VALUE:f[d].created+this.$$maxAge,o.push(f[d]);return"aggressive"===this.$$deleteOnExpire?this.removeExpired():{}},setOnExpire:function(a){if(null===a)delete this.$$onExpire;else{if(!g.isFunction(a))throw new Error("onExpire must be a function!");this.$$onExpire=a}},setOptions:function(a,c){if(a=a||{},c=!!c,!g.isObject(a))throw new Error("cacheOptions must be an object!");"storagePrefix"in a?this.$$storagePrefix=a.storagePrefix:c&&(this.$$storagePrefix=b.storagePrefix),this.$$prefix=this.$$storagePrefix+this.$$id,"disabled"in a?this.$$disabled=!!a.disabled:c&&(this.$$disabled=b.disabled),"storageMode"in a||"storageImpl"in a?this.setStorageMode(a.storageMode,a.storageImpl):c&&this.setStorageMode(b.storageMode,b.storageImpl),"storeOnResolve"in a?this.$$storeOnResolve=!!a.storeOnResolve:c&&(this.$$storeOnResolve=b.storeOnResolve),"storeOnReject"in a?this.$$storeOnReject=!!a.storeOnReject:c&&(this.$$storeOnReject=b.storeOnReject),"capacity"in a?this.setCapacity(a.capacity):c&&this.setCapacity(b.capacity),"deleteOnExpire"in a?this.setDeleteOnExpire(a.deleteOnExpire,!1):c&&this.setDeleteOnExpire(b.deleteOnExpire,!1),"maxAge"in a?this.setMaxAge(a.maxAge):c&&this.setMaxAge(b.maxAge),"recycleFreq"in a?this.setRecycleFreq(a.recycleFreq):c&&this.setRecycleFreq(b.recycleFreq),"cacheFlushInterval"in a?this.setCacheFlushInterval(a.cacheFlushInterval):c&&this.setCacheFlushInterval(b.cacheFlushInterval),"onExpire"in a?this.setOnExpire(a.onExpire):c&&this.setOnExpire(b.onExpire)},setRecycleFreq:function(a){if(null===a)delete this.$$recycleFreq;else{if(!g.isNumber(a))throw new Error("recycleFreq must be a number!");if(0>a)throw new Error("recycleFreq must be greater than zero!");this.$$recycleFreq=a}clearInterval(this.$$recycleFreqId),"aggressive"===this.$$deleteOnExpire?!function(a){a.$$recycleFreqId=setInterval(function(){a.removeExpired()},a.$$recycleFreq)}(this):delete this.$$recycleFreqId},setStorageMode:function(a,b){if(!g.isString(a))throw new Error("storageMode must be a string!");if("memory"!==a&&"localStorage"!==a&&"sessionStorage"!==a)throw new Error('storageMode must be "memory", "localStorage" or "sessionStorage"!');var c=!1,d={};if("string"==typeof this.$$storageMode&&this.$$storageMode!==a){var e=this.keys();if(e.length){for(var f=0;f<e.length;f++)d[e[f]]=this.get(e[f]);for(f=0;f<e.length;f++)this.remove(e[f]);c=!0}}if(this.$$storageMode=a,b){if(!g.isObject(b))throw new Error("storageImpl must be an object!");if(!("setItem"in b&&"function"==typeof b.setItem))throw new Error('storageImpl must implement "setItem(key, value)"!');if(!("getItem"in b&&"function"==typeof b.getItem))throw new Error('storageImpl must implement "getItem(key)"!');if(!("removeItem"in b)||"function"!=typeof b.removeItem)throw new Error('storageImpl must implement "removeItem(key)"!');n=function(){return b}}else if("localStorage"===this.$$storageMode)try{localStorage.setItem("angular-cache","angular-cache"),localStorage.removeItem("angular-cache"),n=function(){return localStorage}}catch(h){n=null,this.$$storageMode="memory"}else if("sessionStorage"===this.$$storageMode)try{sessionStorage.setItem("angular-cache","angular-cache"),sessionStorage.removeItem("angular-cache"),n=function(){return sessionStorage}}catch(h){n=null,this.$$storageMode="memory"}if(c)for(var i in d)this.put(i,d[i])},touch:function(a){var b=this;if(a){var c=this.get(a,{onExpire:function(a,c){return b.put(a,c)}});c&&this.put(a,c)}else for(var d=this.keys(),e=0;e<d.length;e++)this.touch(d[e])}};return q.setOptions(d,!0),q};return d.createCache=f,d.info=function(){var b=h(e),c={size:b.length,caches:{}};g.extend(c,a.defaults);for(var d=0;d<b.length;d++){var f=b[d];c.caches[f]=e[f].info()}return c},d.get=function(a){return e[a]},d.keySet=function(){return k(e)},d.keys=function(){return h(e)},d.destroy=function(a){e[a]&&(e[a].destroy(),delete e[a])},d.destroyAll=function(){for(var a in e)e[a].destroy();e={}},d.clearAll=function(){for(var a in e)e[a].removeAll()},d.removeExpiredFromAll=function(){var a={};for(var b in e)a[b]=e[b].removeExpired();return a},d.enableAll=function(){for(var a in e)e[a].$$disabled=!1},d.disableAll=function(){for(var a in e)e[a].$$disabled=!0},d.touchAll=function(){for(var a in e)e[a].touch()},d}]};g.module("angular-cache",[]).provider("BinaryHeap",n).provider("CacheFactory",o),a.exports="angular-cache"},function(b){b.exports=a}])});
!function(a,b){"object"==typeof exports&&"object"==typeof module?module.exports=b(require("angular")):"function"==typeof define&&define.amd?define(["angular"],b):"object"==typeof exports?exports.angularCacheModuleName=b(require("angular")):a.angularCacheModuleName=b(a.angular)}(this,function(a){return function(a){function b(d){if(c[d])return c[d].exports;var e=c[d]={exports:{},id:d,loaded:!1};return a[d].call(e.exports,e,e.exports,b),e.loaded=!0,e.exports}var c={};return b.m=a,b.c=c,b.p="",b(0)}([function(a,b,c){function d(a,b,c){for(var d=a[c],e=b(d);c>0;){var f=Math.floor((c+1)/2)-1,g=a[f];if(e>=b(g))break;a[f]=d,a[c]=g,c=f}}var e=function(a){return a&&a.__esModule?a["default"]:a},f=function(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")},g=e(c(1)),h=function(a){var b=[],c=void 0;for(c in a)a.hasOwnProperty(c)&&b.push(c);return b},i=function(a){return a&&"function"==typeof a.then},j=function(a){return g.isNumber(a)?a.toString():a},k=function(a){var b={},c=void 0;for(c in a)a.hasOwnProperty(c)&&(b[c]=c);return b},l=function(a,b,c){for(var d=a.length,e=a[c],f=b(e);;){var g=2*(c+1),h=g-1,i=null;if(d>h){var j=a[h],k=b(j);f>k&&(i=h)}if(d>g){var l=a[g],m=b(l);m<(null===i?f:b(a[h]))&&(i=g)}if(null===i)break;a[c]=a[i],a[i]=e,c=i}},m=function p(a,b){var c=this;if(f(this,p),a||(a=function(a){return a}),b||(b=function(a,b){return a===b}),"function"!=typeof a)throw new Error('BinaryHeap([weightFunc][, compareFunc]): "weightFunc" must be a function!');if("function"!=typeof b)throw new Error('BinaryHeap([weightFunc][, compareFunc]): "compareFunc" must be a function!');this.weightFunc=a,this.compareFunc=b,this.heap=[],this.push=function(a){c.heap.push(a),d(c.heap,c.weightFunc,c.heap.length-1)},this.peek=function(){return c.heap.length?c.heap[0]:void 0},this.pop=function(){var a=c.heap[0],b=c.heap.pop();return c.heap.length>0&&(c.heap[0]=b,l(c.heap,c.weightFunc,0)),a},this.remove=function(a){for(var b=c.heap.length,e=0;b>e;e++)if(c.compareFunc(c.heap[e],a)){var f=c.heap[e],g=c.heap.pop();return e!==b-1&&(c.heap[e]=g,d(c.heap,c.weightFunc,e),l(c.heap,c.weightFunc,e)),f}return null},this.removeAll=function(){c.heap=[]},this.size=function(){return c.heap.length}},n=function q(){f(this,q),this.$get=function(){return m}},o=function r(){var a=this;f(this,r);var b=this.defaults={capacity:Number.MAX_VALUE,maxAge:Number.MAX_VALUE,deleteOnExpire:"none",onExpire:null,cacheFlushInterval:null,recycleFreq:1e3,storageMode:"memory",storageImpl:null,disabled:!1,storagePrefix:"angular-cache.caches.",storeOnResolve:!1,storeOnReject:!1};this.$get=["$q",function(c){function d(a,b){return f(a,b)}var e={},f=function(a,d){if(a in e)throw new Error(""+a+" already exists!");if(!g.isString(a))throw new Error("cacheId must be a string!");var f={},l={},n=null,o=new m(function(a){return a.expires},g.equals),p=new m(function(a){return a.accessed},g.equals),q=e[a]={$$id:a,destroy:function(){clearInterval(this.$$cacheFlushIntervalId),clearInterval(this.$$recycleFreqId),this.removeAll(),n&&(n().removeItem(""+this.$$prefix+".keys"),n().removeItem(this.$$prefix)),n=null,f=null,p=null,o=null,this.$$prefix=null,delete e[this.$$id]},disable:function(){this.$$disabled=!0},enable:function(){delete this.$$disabled},get:function(a,b){var c=this;if(g.isArray(a)){var d=function(){var d=a,e=[];return g.forEach(d,function(a){var d=c.get(a,b);null!==d&&void 0!==d&&e.push(d)}),{v:e}}();if("object"==typeof d)return d.v}else if(a=j(a),this.$$disabled)return;if(b=b||{},!g.isString(a))throw new Error("key must be a string!");if(b&&!g.isObject(b))throw new Error("options must be an object!");if(b.onExpire&&!g.isFunction(b.onExpire))throw new Error("options.onExpire must be a function!");var e=void 0;if(n){if(l[a])return l[a];var h=n().getItem(""+this.$$prefix+".data."+a);if(!h)return;e=g.fromJson(h)}else{if(!(a in f))return;e=f[a]}var i=e.value,k=(new Date).getTime();return n?(p.remove({key:a,accessed:e.accessed}),e.accessed=k,p.push({key:a,accessed:k})):(p.remove(e),e.accessed=k,p.push(e)),"passive"===this.$$deleteOnExpire&&"expires"in e&&e.expires<k?(this.remove(a),this.$$onExpire?this.$$onExpire.call(this,a,e.value,b.onExpire):b.onExpire&&b.onExpire.call(this,a,e.value),i=void 0):n&&n().setItem(""+this.$$prefix+".data."+a,JSON.stringify(e)),i},info:function(a){if(a){var b=void 0;if(n){var c=n().getItem(""+this.$$prefix+".data."+a);return c?(b=g.fromJson(c),{created:b.created,accessed:b.accessed,expires:b.expires,isExpired:(new Date).getTime()-b.created>this.$$maxAge}):void 0}return a in f?(b=f[a],{created:b.created,accessed:b.accessed,expires:b.expires,isExpired:(new Date).getTime()-b.created>this.$$maxAge}):void 0}return{id:this.$$id,capacity:this.$$capacity,maxAge:this.$$maxAge,deleteOnExpire:this.$$deleteOnExpire,onExpire:this.$$onExpire,cacheFlushInterval:this.$$cacheFlushInterval,recycleFreq:this.$$recycleFreq,storageMode:this.$$storageMode,storageImpl:n?n():void 0,disabled:!!this.$$disabled,size:p&&p.size()||0}},keys:function(){if(n){var a=n().getItem(""+this.$$prefix+".keys");return a?g.fromJson(a):[]}return h(f)},keySet:function(){if(n){var a=n().getItem(""+this.$$prefix+".keys"),b={};if(a)for(var c=g.fromJson(a),d=0;d<c.length;d++)b[c[d]]=c[d];return b}return k(f)},put:function(a,b,d){var e=this;d=d||{};var h="storeOnResolve"in d?!!d.storeOnResolve:this.$$storeOnResolve,k="storeOnReject"in d?!!d.storeOnReject:this.$$storeOnReject,m=function(b,d){return function(f){return b&&(delete l[a],g.isObject(f)&&"status"in f&&"data"in f?(f=[f.status,f.data,f.headers(),f.statusText],e.put(a,f)):e.put(a,f)),d?c.reject(f):f}};if(!this.$$disabled&&null!==b&&void 0!==b){if(a=j(a),!g.isString(a))throw new Error("key must be a string!");var q=(new Date).getTime(),r={key:a,value:i(b)?b.then(m(h,!1),m(k,!0)):b,created:q,accessed:q};if(r.expires=r.created+this.$$maxAge,n){if(i(r.value))return l[a]=r.value,l[a];var s=n().getItem(""+this.$$prefix+".keys"),t=s?g.fromJson(s):[],u=n().getItem(""+this.$$prefix+".data."+a);u&&this.remove(a),o.push({key:a,expires:r.expires}),p.push({key:a,accessed:r.accessed}),n().setItem(""+this.$$prefix+".data."+a,JSON.stringify(r));for(var v=!1,w=0;w<t.length;w++)if(t[w]===a){v=!0;break}v||t.push(a),n().setItem(""+this.$$prefix+".keys",JSON.stringify(t))}else f[a]&&this.remove(a),o.push(r),p.push(r),f[a]=r,delete l[a];return p.size()>this.$$capacity&&this.remove(p.peek().key),b}},remove:function(a){if(a+="",delete l[a],!n){var b=f[a]?f[a].value:void 0;return p.remove(f[a]),o.remove(f[a]),f[a]=null,delete f[a],b}var c=n().getItem(""+this.$$prefix+".data."+a);if(c){var d=g.fromJson(c);p.remove({key:a,accessed:d.accessed}),o.remove({key:a,expires:d.expires}),n().removeItem(""+this.$$prefix+".data."+a);var e=n().getItem(""+this.$$prefix+".keys"),h=e?g.fromJson(e):[],i=h.indexOf(a);return i>=0&&h.splice(i,1),n().setItem(""+this.$$prefix+".keys",JSON.stringify(h)),d.value}},removeAll:function(){if(n){p.removeAll(),o.removeAll();var a=n().getItem(""+this.$$prefix+".keys");if(a)for(var b=g.fromJson(a),c=0;c<b.length;c++)this.remove(b[c]);n().setItem(""+this.$$prefix+".keys",JSON.stringify([]))}else{p.removeAll(),o.removeAll();for(var d in f)f[d]=null;f={}}l={}},removeExpired:function(){for(var a=(new Date).getTime(),b={},c=void 0,d=void 0;(d=o.peek())&&d.expires<=a;)b[d.key]=d.value?d.value:null,o.pop();if(n)for(c in b){var e=n().getItem(""+this.$$prefix+".data."+c);e&&(b[c]=g.fromJson(e).value,this.remove(c))}else for(c in b)this.remove(c);if(this.$$onExpire)for(c in b)this.$$onExpire.call(this,c,b[c]);return b},setCacheFlushInterval:function(a){if(null===a)delete this.$$cacheFlushInterval;else{if(!g.isNumber(a))throw new Error("cacheFlushInterval must be a number!");if(0>a)throw new Error("cacheFlushInterval must be greater than zero!");a!==this.$$cacheFlushInterval&&(this.$$cacheFlushInterval=a,clearInterval(this.$$cacheFlushIntervalId),function(a){a.$$cacheFlushIntervalId=setInterval(function(){a.removeAll()},a.$$cacheFlushInterval)}(this))}},setCapacity:function(a){if(null===a)delete this.$$capacity;else{if(!g.isNumber(a))throw new Error("capacity must be a number!");if(0>a)throw new Error("capacity must be greater than zero!");this.$$capacity=a}for(var b={};p.size()>this.$$capacity;)b[p.peek().key]=this.remove(p.peek().key);return b},setDeleteOnExpire:function(a,b){if(null===a)delete this.$$deleteOnExpire;else{if(!g.isString(a))throw new Error("deleteOnExpire must be a string!");if("none"!==a&&"passive"!==a&&"aggressive"!==a)throw new Error('deleteOnExpire must be "none", "passive" or "aggressive"!');this.$$deleteOnExpire=a}b!==!1&&this.setRecycleFreq(this.$$recycleFreq)},setMaxAge:function(a){if(null===a)this.$$maxAge=Number.MAX_VALUE;else{if(!g.isNumber(a))throw new Error("maxAge must be a number!");if(0>a)throw new Error("maxAge must be greater than zero!");this.$$maxAge=a}var b=void 0,c=void 0,d=void 0;if(o.removeAll(),n){var e=n().getItem(""+this.$$prefix+".keys");for(c=e?g.fromJson(e):[],b=0;b<c.length;b++){d=c[b];var i=n().getItem(""+this.$$prefix+".data."+d);if(i){var j=g.fromJson(i);j.expires=this.$$maxAge===Number.MAX_VALUE?Number.MAX_VALUE:j.created+this.$$maxAge,o.push({key:d,expires:j.expires})}}}else for(c=h(f),b=0;b<c.length;b++)d=c[b],f[d].expires=this.$$maxAge===Number.MAX_VALUE?Number.MAX_VALUE:f[d].created+this.$$maxAge,o.push(f[d]);return"aggressive"===this.$$deleteOnExpire?this.removeExpired():{}},setOnExpire:function(a){if(null===a)delete this.$$onExpire;else{if(!g.isFunction(a))throw new Error("onExpire must be a function!");this.$$onExpire=a}},setOptions:function(a,c){if(a=a||{},c=!!c,!g.isObject(a))throw new Error("cacheOptions must be an object!");"storagePrefix"in a?this.$$storagePrefix=a.storagePrefix:c&&(this.$$storagePrefix=b.storagePrefix),this.$$prefix=this.$$storagePrefix+this.$$id,"disabled"in a?this.$$disabled=!!a.disabled:c&&(this.$$disabled=b.disabled),"storageMode"in a||"storageImpl"in a?this.setStorageMode(a.storageMode,a.storageImpl):c&&this.setStorageMode(b.storageMode,b.storageImpl),"storeOnResolve"in a?this.$$storeOnResolve=!!a.storeOnResolve:c&&(this.$$storeOnResolve=b.storeOnResolve),"storeOnReject"in a?this.$$storeOnReject=!!a.storeOnReject:c&&(this.$$storeOnReject=b.storeOnReject),"capacity"in a?this.setCapacity(a.capacity):c&&this.setCapacity(b.capacity),"deleteOnExpire"in a?this.setDeleteOnExpire(a.deleteOnExpire,!1):c&&this.setDeleteOnExpire(b.deleteOnExpire,!1),"maxAge"in a?this.setMaxAge(a.maxAge):c&&this.setMaxAge(b.maxAge),"recycleFreq"in a?this.setRecycleFreq(a.recycleFreq):c&&this.setRecycleFreq(b.recycleFreq),"cacheFlushInterval"in a?this.setCacheFlushInterval(a.cacheFlushInterval):c&&this.setCacheFlushInterval(b.cacheFlushInterval),"onExpire"in a?this.setOnExpire(a.onExpire):c&&this.setOnExpire(b.onExpire)},setRecycleFreq:function(a){if(null===a)delete this.$$recycleFreq;else{if(!g.isNumber(a))throw new Error("recycleFreq must be a number!");if(0>a)throw new Error("recycleFreq must be greater than zero!");this.$$recycleFreq=a}clearInterval(this.$$recycleFreqId),"aggressive"===this.$$deleteOnExpire?!function(a){a.$$recycleFreqId=setInterval(function(){a.removeExpired()},a.$$recycleFreq)}(this):delete this.$$recycleFreqId},setStorageMode:function(a,b){if(!g.isString(a))throw new Error("storageMode must be a string!");if("memory"!==a&&"localStorage"!==a&&"sessionStorage"!==a)throw new Error('storageMode must be "memory", "localStorage" or "sessionStorage"!');var c=!1,d={};if("string"==typeof this.$$storageMode&&this.$$storageMode!==a){var e=this.keys();if(e.length){for(var f=0;f<e.length;f++)d[e[f]]=this.get(e[f]);for(f=0;f<e.length;f++)this.remove(e[f]);c=!0}}if(this.$$storageMode=a,b){if(!g.isObject(b))throw new Error("storageImpl must be an object!");if(!("setItem"in b&&"function"==typeof b.setItem))throw new Error('storageImpl must implement "setItem(key, value)"!');if(!("getItem"in b&&"function"==typeof b.getItem))throw new Error('storageImpl must implement "getItem(key)"!');if(!("removeItem"in b)||"function"!=typeof b.removeItem)throw new Error('storageImpl must implement "removeItem(key)"!');n=function(){return b}}else if("localStorage"===this.$$storageMode)try{localStorage.setItem("angular-cache","angular-cache"),localStorage.removeItem("angular-cache"),n=function(){return localStorage}}catch(h){n=null,this.$$storageMode="memory"}else if("sessionStorage"===this.$$storageMode)try{sessionStorage.setItem("angular-cache","angular-cache"),sessionStorage.removeItem("angular-cache"),n=function(){return sessionStorage}}catch(h){n=null,this.$$storageMode="memory"}if(c)for(var i in d)this.put(i,d[i])},touch:function(a){var b=this;if(a){var c=this.get(a,{onExpire:function(a,c){return b.put(a,c)}});c&&this.put(a,c)}else for(var d=this.keys(),e=0;e<d.length;e++)this.touch(d[e])}};return q.setOptions(d,!0),q};return d.createCache=f,d.info=function(){var b=h(e),c={size:b.length,caches:{}};g.extend(c,a.defaults);for(var d=0;d<b.length;d++){var f=b[d];c.caches[f]=e[f].info()}return c},d.get=function(a){return e[a]},d.keySet=function(){return k(e)},d.keys=function(){return h(e)},d.destroy=function(a){e[a]&&(e[a].destroy(),delete e[a])},d.destroyAll=function(){for(var a in e)e[a].destroy();e={}},d.clearAll=function(){for(var a in e)e[a].removeAll()},d.removeExpiredFromAll=function(){var a={};for(var b in e)a[b]=e[b].removeExpired();return a},d.enableAll=function(){for(var a in e)e[a].$$disabled=!1},d.disableAll=function(){for(var a in e)e[a].$$disabled=!0},d.touchAll=function(){for(var a in e)e[a].touch()},d}]};g.module("angular-cache",[]).provider("BinaryHeap",n).provider("CacheFactory",o),a.exports="angular-cache"},function(b){b.exports=a}])});
//# sourceMappingURL=angular-cache.min.map
{
"name": "angular-cache",
"description": "angular-cache is a very useful replacement for Angular's $cacheFactory.",
"version": "4.1.0",
"version": "4.2.0",
"homepage": "http://jmdobry.github.io/angular-cache/",

@@ -6,0 +6,0 @@ "main": "dist/angular-cache.js",

@@ -25,3 +25,3 @@ import angular from 'angular';

let _keySet = collection => {
var keySet = {}, key;
let keySet = {}, key;
for (key in collection) {

@@ -126,5 +126,3 @@ if (collection.hasOwnProperty(key)) {

this.peek = () => {
return this.heap[0];
};
this.peek = () => this.heap.length ? this.heap[0] : undefined;

@@ -142,4 +140,4 @@ this.pop = () => {

this.remove = node => {
var length = this.heap.length;
for (let i = 0; i < length; i++) {
let length = this.heap.length;
for (var i = 0; i < length; i++) {
if (this.compareFunc(this.heap[i], node)) {

@@ -163,5 +161,3 @@ let removed = this.heap[i];

this.size = () => {
return this.heap.length;
};
this.size = () => this.heap.length;
}

@@ -178,3 +174,3 @@ }

constructor() {
var defaults = this.defaults = {
let defaults = this.defaults = {
capacity: Number.MAX_VALUE,

@@ -329,3 +325,3 @@ maxAge: Number.MAX_VALUE,

if ($$storage) {
var itemJson = $$storage().getItem(`${this.$$prefix}.data.${key}`);
let itemJson = $$storage().getItem(`${this.$$prefix}.data.${key}`);

@@ -394,3 +390,3 @@ if (itemJson) {

if (keysJson) {
var keys = angular.fromJson(keysJson);
let keys = angular.fromJson(keysJson);

@@ -441,4 +437,4 @@ for (var i = 0; i < keys.length; i++) {

var now = new Date().getTime();
var item = {
let now = new Date().getTime();
let item = {
key: key,

@@ -457,5 +453,5 @@ value: _isPromiseLike(value) ? value.then(getHandler(storeOnResolve, false), getHandler(storeOnReject, true)) : value,

}
var keysJson = $$storage().getItem(`${this.$$prefix}.keys`);
var keys = keysJson ? angular.fromJson(keysJson) : [];
var itemJson = $$storage().getItem(`${this.$$prefix}.data.${key}`);
let keysJson = $$storage().getItem(`${this.$$prefix}.keys`);
let keys = keysJson ? angular.fromJson(keysJson) : [];
let itemJson = $$storage().getItem(`${this.$$prefix}.data.${key}`);

@@ -478,3 +474,3 @@ // Remove existing

$$storage().setItem(`${this.$$prefix}.data.${key}`, JSON.stringify(item));
var exists = false;
let exists = false;
for (var i = 0; i < keys.length; i++) {

@@ -540,3 +536,3 @@ if (keys[i] === key) {

} else {
var value = $$data[key] ? $$data[key].value : undefined;
let value = $$data[key] ? $$data[key].value : undefined;
$$lruHeap.remove($$data[key]);

@@ -572,2 +568,3 @@ $$expiresHeap.remove($$data[key]);

}
$$promises = {};
},

@@ -588,3 +585,3 @@

for (key in expired) {
var itemJson = $$storage().getItem(`${this.$$prefix}.data.${key}`);
let itemJson = $$storage().getItem(`${this.$$prefix}.data.${key}`);
if (itemJson) {

@@ -638,3 +635,3 @@ expired[key] = angular.fromJson(itemJson).value;

}
var removed = {};
let removed = {};
while ($$lruHeap.size() > this.$$capacity) {

@@ -641,0 +638,0 @@ removed[$$lruHeap.peek().key] = this.remove($$lruHeap.peek().key);

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc