-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaches.min.js
8 lines (8 loc) · 3.14 KB
/
caches.min.js
1
2
3
4
5
6
7
8
/**
* angular-hu-caches v1.1.0
* https://github.com/angular-hu/angular-hu
* (c) 2015 Telefónica I+D - http://www.tid.es
* @license MIT
*/
!function(n){"use strict";function e(){return{stringify:JSON.stringify,parse:JSON.parse}}function t(e){return function(t,r){function i(n){return S+".i."+(n||"")}function o(n){return n&&"function"==typeof n.then}function u(n,e){try{return w.setItem(n,e),!0}catch(t){return!1}}function a(n,e){if(!u(n,e)){var t=[];if(r.forEach(function(n,e){t.push({k:e,v:n})}),!u(n,e))for(var i=t.length-1;i>=0;--i){var o=t[i];if(h(o.k,o.v),u(n,e))break}}}function c(){var e={};return n.forEach(r.toJSON(),function(n){o(n.v)||(e[n.k]=n.n)}),e}function f(){E={};var n=JSON.stringify(c());a(k,n)}function l(e,t){if(!o(t)){var r;n.isDefined(E[e])?(r=E[e],delete E[e]):r=C.stringify(t),a(i(e),r),v()}}function h(n,e){o(e)||(w.removeItem(i(n)),v())}function s(n,e){o(e)||v()}function g(){e.cancel(x),E=null,n.forEach(d(),function(n){w.removeItem(n)}),w.removeItem(k)}function v(){x||(x=e(function(){f(),x=null}))}function d(){for(var n=[],e=i(),t=0,r=w.length;r>t;t++){var o=w.key(t);-1!==o.indexOf(e)&&n.push(o)}return n}function m(){var e=d(),t=[];n.forEach(r.toJSON(),function(n){t.push(i(n.k))}),n.forEach(e,function(n){-1===t.indexOf(n)&&w.removeItem(n)}),f()}function y(){var e,t=[];try{e=JSON.parse(w.getItem(k))}catch(o){}n.forEach(e,function(n,e){var r=w.getItem(i(e));if(null!==r)try{var o=C.parse(r);E[e]=r,t.push({k:e,v:o,n:n})}catch(u){}}),r.load(t),m()}function p(n,e){return o(e)?0:(E[n]=E[n]||C.stringify(e),E[n].length+i(n).length+n.length+4+(t.maxAge?13:0))}var x,E={},S="hucsss."+t.id,k=S+".l",w=t.storage,C=t.serializer;return{put:l,remove:h,get:s,destroy:g,load:y,lengthCalculator:p}}}function r(r,i){function o(o,u){function a(n,e){v.remove(n,e)}function l(n,e){return v.lengthCalculator.call(v,e,n)}if(u=u||{},o in f)throw new Error("huCacheSerializableFactory: CacheId "+o+" is already taken!");if(n.isDefined(u.capacity)&&n.isDefined(u.maxLength))throw new Error("huCacheSerializableFactory: you must choose between capacity OR maxLength");var h=n.extend({id:o,serializer:e,storage:r.localStorage},u);h.serializer=c(h.serializer);var s={maxAge:u.maxAge,dispose:a,length:l};s.max=n.isDefined(u.maxLength)?u.maxLength:u.capacity||Number.MAX_VALUE-1;var g=new r.LRUCache(s),v=i.invoke(t)(h,g);return n.isDefined(u.maxLength)||(v.lengthCalculator=function(){return 1}),v.load(),f[o]={put:function(e,t){if(n.isUndefined(t))return void 0;var r=g.set(e,t);return r&&v.put(e,t),r?t:void 0},get:function(n){var e=g.get(n);return e&&v.get(n,e),e},remove:function(n){g.del(n)},removeAll:function(){g.reset()},destroy:function(){v.destroy(),v=null,g=null,delete f[o]},info:function(){var e=n.extend({},u,{id:o,size:g.itemCount});return e.length=g.length,e},prune:function(){g.forEach(n.noop)}},f[o]}function u(){var e={};return n.forEach(f,function(n,t){e[t]=n.info()}),e}function a(n){return f[n]}function c(e){return n.isString(e)?i.get(e):i.invoke(e)}var f={};return o.info=u,o.get=a,o}n.module("httpu.caches",[]).factory("huCacheSerializableFactory",r),e.$inject=[],t.$inject=["$timeout"],r.$inject=["$window","$injector"]}(window.angular);
//# sourceMappingURL=caches.min.js.map