-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathflexicache.min.js
12 lines (12 loc) · 3.03 KB
/
flexicache.min.js
1
2
3
4
5
6
7
8
9
10
11
12
/*
https://github.com/nextapps-de/flexicache
@version: 0.1.13
@author: Thomas Wilkerling
@license: Apache 2.0 Licence
*/
'use strict';(function(c,f,e){e||(e=this);var a;(a=e.define)&&a.amd?a([],function(){return f}):(a=e.modules)?a[c.toLowerCase()]=f:"undefined"!==typeof module?module.exports=f:e[c]=f})("FlexiCache",function(c,f){function e(b,d){this.data=b;this.time=h();this.b="number"===typeof d&&this.time+d;this.count=0}function a(b,d,a){this.f=k++;this.a=[];this.data={};this.duration=!1===b?!1:b||18E4;this.size=!1===d?!1:d||1E3;this.auto=!!a;this.c=this.async=!1;Object.defineProperty(this,"length",{get:function(){return this.a.length}})}
function g(){if(this.duration||this.auto){var b=this;f(function(){b.cleanup();b=void 0},this.auto?6E4:this.duration,"cache-cleanup-"+this.f)}}function h(){return"undefined"!==typeof performance?performance.now():(new Date).getTime()}var k=0;e.prototype.clone=function(){this.count++;return c(this.data)};a.register=function(b,d,c){return new a(b,d,c)};a.create=function(b,d,c){return a.register(b,d,c)};a.new=function(b,d,c){return a.register(b,d,c)};a.prototype.set=function(b,d,a){return this.add(b,
d,a)};a.prototype.add=function(b,d,a){if(b=""+b){var c=this.data[b];c?(c.data=d,c.time=h(),c.b=c.time+(a||this.duration||0)):(c=this.a.length,this.size&&c>=this.size&&(this.del(this.a[0]),c--),this.data[b]=new e(d,!1===a?!1:a||this.duration),this.a[c]=b);this.c||(g.call(this),this.c=!0);return d}};a.prototype.copy=function(b,a){return this.set(b,c(a))};a.prototype.get=function(b,a){if(b){var c=this.data[b];if(c){if(a||!c.b||h()<c.b)return c.count++,c.data;this.del(b)}}};a.prototype.clone=function(b,
a){return c(this.get(b,a))};a.prototype.all=function(){return this.data};a.prototype.remove=function(b){var a=this.data[b].data;this.del(b);return a};a.prototype.rm=function(b){return this.remove(b)};a.prototype.del=function(b){this.delete(b)};a.prototype.delete=function(b){if(b&&this.data[b]){for(var a=0;a<this.a.length;a++)if(this.a[a]===b){this.a.splice(a,1);break}this.data[b].data=null;this.data[b]=null;delete this.data[b]}};a.prototype.reset=function(){this.data={};this.a=[]};a.prototype.count=
function(){return this.a.length};a.prototype.cleanup=function(a){if(this.a.length)for(var b=h(),c=0;c<this.a.length;c++){var e=this.a[c],f=this.data[e];f.b&&b>f.b?(this.del(e),c--):this.auto&&0===f.count&&(a||6E4<b-f.time)?(this.del(e),c--):f.count=0}this.a.length?g.call(this):this.c=!1};return a}(function l(c){if(c&&"object"===typeof c){if(c.cloneNode)return c.cloneNode(!0);switch(c.constructor){case Date:return new Date(c);case RegExp:return new RegExp(c);case Array:var e=c.length,a=Array(e);if(e)for(var g=
0;g<e;)d=c[g],b=typeof d,a[g]="number"===b||"string"===b||"boolean"===b?d:l(d),g++;return a;case Object:var h=Object.keys(c);e=h.length;a={};if(e){g=0;for(var k,b,d;g<e;)k=h[g++],d=c[k],b=typeof d,a[k]="number"===b||"string"===b||"boolean"===b?d:l(d)}return a;default:if(c.clone)return c.clone()}}return c},function(){var c={};return function(f,e,a){var g=c[a];g&&clearTimeout(g);return c[a]=setTimeout(f,e)}}()),this);