From 9ba05749b3a7d1fa7daa7a49dee3c5c58b0f622d Mon Sep 17 00:00:00 2001 From: Jason Dobry Date: Wed, 1 Jul 2015 11:13:20 -0400 Subject: [PATCH] Stable Version 4.2.2. Fixes #165 --- CHANGELOG.md | 11 +++++++++++ dist/angular-cache.js | 4 ++-- dist/angular-cache.min.js | 4 ++-- dist/angular-cache.min.map | 2 +- package.json | 2 +- src/index.js | 2 +- test/unit/DSCacheFactory/index.test.js | 3 +++ 7 files changed, 21 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5688309..11996c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +##### 4.2.2 1 July 2015 + +###### Backwards compatible bug fixes +- #165 - storageMode does not inherits from defaults + +##### 4.2.1 1 July 2015 + +Upgraded dependencies +Better CommonJS interop +Added a number of build examples + ##### 4.2.0 27 April 2015 ###### Backwards compatible bug fixes diff --git a/dist/angular-cache.js b/dist/angular-cache.js index cd84b13..9b922ff 100644 --- a/dist/angular-cache.js +++ b/dist/angular-cache.js @@ -1,6 +1,6 @@ /*! * angular-cache - * @version 4.2.1 - Homepage + * @version 4.2.2 - Homepage * @author Jason Dobry * @copyright (c) 2013-2015 Jason Dobry * @license MIT @@ -829,7 +829,7 @@ return /******/ (function(modules) { // webpackBootstrap } if ('storageMode' in cacheOptions || 'storageImpl' in cacheOptions) { - this.setStorageMode(cacheOptions.storageMode, cacheOptions.storageImpl); + this.setStorageMode(cacheOptions.storageMode || defaults.storageMode, cacheOptions.storageImpl || defaults.storageImpl); } else if (strict) { this.setStorageMode(defaults.storageMode, defaults.storageImpl); } diff --git a/dist/angular-cache.min.js b/dist/angular-cache.min.js index 502ed24..584b577 100644 --- a/dist/angular-cache.min.js +++ b/dist/angular-cache.min.js @@ -1,6 +1,6 @@ /*! * angular-cache -* @version 4.2.1 - Homepage +* @version 4.2.2 - Homepage * @author Jason Dobry * @copyright (c) 2013-2015 Jason Dobry * @license MIT @@ -8,5 +8,5 @@ * @overview angular-cache is a very useful replacement for Angular's $cacheFactory. */ -!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){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function e(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 f=c(1),g=function(a){var b=[],c=void 0;for(c in a)a.hasOwnProperty(c)&&b.push(c);return b},h=function(a){return a&&"function"==typeof a.then},i=function(a){return f.isNumber(a)?a.toString():a},j=function(a){var b={},c=void 0;for(c in a)a.hasOwnProperty(c)&&(b[c]=c);return b},k=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}},l=function o(a,b){var c=this;if(d(this,o),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),e(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,k(c.heap,c.weightFunc,0)),a},this.remove=function(a){for(var b=c.heap.length,d=0;b>d;d++)if(c.compareFunc(c.heap[d],a)){var f=c.heap[d],g=c.heap.pop();return d!==b-1&&(c.heap[d]=g,e(c.heap,c.weightFunc,d),k(c.heap,c.weightFunc,d)),f}return null},this.removeAll=function(){c.heap=[]},this.size=function(){return c.heap.length}},m=function p(){d(this,p),this.$get=function(){return l}},n=function q(){var a=this;d(this,q);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 k(a,b)}var e={},k=function(a,d){if(a in e)throw new Error(a+" already exists!");if(!f.isString(a))throw new Error("cacheId must be a string!");var k={},m={},n=null,o=new l(function(a){return a.expires},f.equals),p=new l(function(a){return a.accessed},f.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,k=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(f.isArray(a)){var d=function(){var d=a,e=[];return f.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=i(a),this.$$disabled)return;if(b=b||{},!f.isString(a))throw new Error("key must be a string!");if(b&&!f.isObject(b))throw new Error("options must be an object!");if(b.onExpire&&!f.isFunction(b.onExpire))throw new Error("options.onExpire must be a function!");var e=void 0;if(n){if(m[a])return m[a];var g=n().getItem(this.$$prefix+".data."+a);if(!g)return;e=f.fromJson(g)}else{if(!(a in k))return;e=k[a]}var h=e.value,j=(new Date).getTime();return n?(p.remove({key:a,accessed:e.accessed}),e.accessed=j,p.push({key:a,accessed:j})):(p.remove(e),e.accessed=j,p.push(e)),"passive"===this.$$deleteOnExpire&&"expires"in e&&e.expiresthis.$$maxAge}):void 0}return a in k?(b=k[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?f.fromJson(a):[]}return g(k)},keySet:function(){if(n){var a=n().getItem(this.$$prefix+".keys"),b={};if(a)for(var c=f.fromJson(a),d=0;dthis.$$capacity&&this.remove(p.peek().key),b}},remove:function(a){if(a+="",delete m[a],!n){var b=k[a]?k[a].value:void 0;return p.remove(k[a]),o.remove(k[a]),k[a]=null,delete k[a],b}var c=n().getItem(this.$$prefix+".data."+a);if(c){var d=f.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"),g=e?f.fromJson(e):[],h=g.indexOf(a);return h>=0&&g.splice(h,1),n().setItem(this.$$prefix+".keys",JSON.stringify(g)),d.value}},removeAll:function(){if(n){p.removeAll(),o.removeAll();var a=n().getItem(this.$$prefix+".keys");if(a)for(var b=f.fromJson(a),c=0;ca)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(!f.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(!f.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(!f.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?f.fromJson(e):[],b=0;ba)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(!f.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 g=0;g0;){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 f=c(1),g=function(a){var b=[],c=void 0;for(c in a)a.hasOwnProperty(c)&&b.push(c);return b},h=function(a){return a&&"function"==typeof a.then},i=function(a){return f.isNumber(a)?a.toString():a},j=function(a){var b={},c=void 0;for(c in a)a.hasOwnProperty(c)&&(b[c]=c);return b},k=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}},l=function o(a,b){var c=this;if(d(this,o),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),e(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,k(c.heap,c.weightFunc,0)),a},this.remove=function(a){for(var b=c.heap.length,d=0;b>d;d++)if(c.compareFunc(c.heap[d],a)){var f=c.heap[d],g=c.heap.pop();return d!==b-1&&(c.heap[d]=g,e(c.heap,c.weightFunc,d),k(c.heap,c.weightFunc,d)),f}return null},this.removeAll=function(){c.heap=[]},this.size=function(){return c.heap.length}},m=function p(){d(this,p),this.$get=function(){return l}},n=function q(){var a=this;d(this,q);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 k(a,b)}var e={},k=function(a,d){if(a in e)throw new Error(a+" already exists!");if(!f.isString(a))throw new Error("cacheId must be a string!");var k={},m={},n=null,o=new l(function(a){return a.expires},f.equals),p=new l(function(a){return a.accessed},f.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,k=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(f.isArray(a)){var d=function(){var d=a,e=[];return f.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=i(a),this.$$disabled)return;if(b=b||{},!f.isString(a))throw new Error("key must be a string!");if(b&&!f.isObject(b))throw new Error("options must be an object!");if(b.onExpire&&!f.isFunction(b.onExpire))throw new Error("options.onExpire must be a function!");var e=void 0;if(n){if(m[a])return m[a];var g=n().getItem(this.$$prefix+".data."+a);if(!g)return;e=f.fromJson(g)}else{if(!(a in k))return;e=k[a]}var h=e.value,j=(new Date).getTime();return n?(p.remove({key:a,accessed:e.accessed}),e.accessed=j,p.push({key:a,accessed:j})):(p.remove(e),e.accessed=j,p.push(e)),"passive"===this.$$deleteOnExpire&&"expires"in e&&e.expiresthis.$$maxAge}):void 0}return a in k?(b=k[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?f.fromJson(a):[]}return g(k)},keySet:function(){if(n){var a=n().getItem(this.$$prefix+".keys"),b={};if(a)for(var c=f.fromJson(a),d=0;dthis.$$capacity&&this.remove(p.peek().key),b}},remove:function(a){if(a+="",delete m[a],!n){var b=k[a]?k[a].value:void 0;return p.remove(k[a]),o.remove(k[a]),k[a]=null,delete k[a],b}var c=n().getItem(this.$$prefix+".data."+a);if(c){var d=f.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"),g=e?f.fromJson(e):[],h=g.indexOf(a);return h>=0&&g.splice(h,1),n().setItem(this.$$prefix+".keys",JSON.stringify(g)),d.value}},removeAll:function(){if(n){p.removeAll(),o.removeAll();var a=n().getItem(this.$$prefix+".keys");if(a)for(var b=f.fromJson(a),c=0;ca)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(!f.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(!f.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(!f.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?f.fromJson(e):[],b=0;ba)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(!f.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 g=0;g