/**
* Unicache
* An agnostic caching framework for PHP, JavaScript, Python
*
* @version: 1.3.0
* https://github.com/foo123/Unicache
*
**/
!function(n,e,t){"use strict";"object"==typeof module&&module.exports?(module.$deps=module.$deps||{})&&(module.exports=module.$deps[e]=t.call(n)):"function"==typeof define&&define.amd&&"function"==typeof require&&"function"==typeof require.specified&&require.specified(e)?define(e,["module"],function(e){return t.moduleUri=e.uri,t.call(n)}):e in n||(n[e]=t.call(n)||1)&&"function"==typeof define&&define.amd&&define(function(){return n[e]})}("undefined"!=typeof self?self:this,"UNICACHE",function(e){"use strict";var n,t,o,i,r,u,c,f,s,p,h,l,a="prototype",d=new Error("Not Implemented!"),y={Cache:function(){}},g=(y.Cache[a]={constructor:y.Cache,dispose:function(){return this},supportsSync:function(){return!1},prefix:"",setPrefix:function(e){return this.prefix=e?String(e):"",this},get:function(e,n){throw d},put:function(e,n,t,i){throw d},remove:function(e,n){throw d},clear:function(e){throw d},gc:function(e,n){throw d},getPromise:function(e){var n=this;return"function"==typeof Promise?new Promise(function(t,i){n.get(e,function(e,n){e?i(e):t(n)})}):null},putPromise:function(e,n,o){var r=this;return"function"==typeof Promise?new Promise(function(t,i){r.put(e,n,o,function(e,n){e?i(e):t(n)})}):null},removePromise:function(e){var n=this;return"function"==typeof Promise?new Promise(function(t,i){n.remove(e,function(e,n){e?i(e):t(n)})}):null},clearPromise:function(){var e=this;return"function"==typeof Promise?new Promise(function(t,i){e.clear(function(e,n){e?i(e):t(n)})}):null},gcPromise:function(e){var n=this;return"function"==typeof Promise?new Promise(function(t,i){n.gc(e,function(e,n){e?i(e):t(n)})}):null}},y._={ESC_RE:/([[\]().?/*{}+$^:\\])/g,TRIM_RE:null,LTRIM_RE:null,RTRIM_RE:null,time:function(){return Math.floor((new Date).getTime()/1e3)},serialize:function(e){return JSON.stringify(e)},unserialize:function(e){return JSON.parse(e)},isset:function(e,n,t){var i=!(!e||!Object.prototype.hasOwnProperty.call(e,n));return!0===t?i&&null!=e[n]:i},trim:function(e,n){n=arguments.length<2?(this.TRIM_RE||(this.TRIM_RE=new RegExp("^[ \\s ]+|[ \\s ]+$","g")),this.TRIM_RE):(n=String(n).replace(this.ESC_RE,"\\$1"),new RegExp("^["+n+"]+|["+n+"]+$","g"));return String(e).replace(n,"")},ltrim:function(e,n){n=arguments.length<2?(this.LTRIM_RE||(this.LTRIM_RE=new RegExp("^[ \\s ]+","g")),this.LTRIM_RE):(n=String(n).replace(this.ESC_RE,"\\$1"),new RegExp("^["+n+"]+","g"));return String(e).replace(n,"")},rtrim:function(e,n){n=arguments.length<2?(this.RTRIM_RE||(this.RTRIM_RE=new RegExp("[ \\s ]+$","g")),this.RTRIM_RE):(n=String(n).replace(this.ESC_RE,"\\$1"),new RegExp("["+n+"]+$","g"));return String(e).replace(n,"")}});function m(e){return encodeURIComponent(String(e)).split("!").join("%21").split("'").join("%27").split("(").join("%28").split(")").join("%29").split("*").join("%2A")}function x(e){return e=String(e).split("+").join("%20"),decodeURIComponent(String(e))}function S(e){var n=!!e.raw,t=(n?u+String(e.name):(t=u+String(e.name),m(String(t)).split("%20").join("+")))+"=";null==e.value||""===e.value?t+="deleted; expires="+new Date(1e3*(c.time()-31536001)).toUTCString():(t+=(n?String:m)(e.value),0!==e.expires&&(t+="; expires="+new Date(1e3*e.expires).toUTCString())),e.path&&(t+="; path="+String(e.path)),e.domain&&(t+="; domain="+String(e.domain)),document.cookie=t}function E(e){S({name:e,value:null})}function v(e,n,t,i){e.executeSql(n,t,function(e,n){"function"==typeof i&&i(null,n)},function(e,n){"function"==typeof i&&i(n,null)})}function I(e,n,t,i){e.transaction(function(e){v(e,'DELETE FROM "'+p+n+'" WHERE key=?',[t],function(e,n){"function"==typeof i&&i(e,n)})},function(e){"function"==typeof i&&i(e,null)})}return y.Factory=function(){},y.Factory.VERSION="1.3.0",y.Factory.getCache=function(e){for(var n=0,t=(e="[object Array]"!==Object[a].toString.call(e)?[e]:e).length;n<t;++n){var i=e[n];if(i){var o=null;switch(g.isset(i,"cacheType",!0)?String(i.cacheType).toUpperCase():"MEMORY"){case"INDEXEDDB":y.IndexedDbCache&&y.IndexedDbCache.isSupported()&&(o=new y.IndexedDbCache);break;case"WEBSQL":y.WebSqlCache&&y.WebSqlCache.isSupported()&&(o=new y.WebSqlCache);break;case"SESSIONSTORAGE":y.SessionStorageCache&&y.SessionStorageCache.isSupported()&&(o=new y.SessionStorageCache);break;case"LOCALSTORAGE":y.LocalStorageCache&&y.LocalStorageCache.isSupported()&&(o=new y.LocalStorageCache);break;case"COOKIE":y.CookieCache&&y.CookieCache.isSupported()&&(o=new y.CookieCache);break;case"MEMORY":y.MemoryCache&&y.MemoryCache.isSupported()&&(o=new y.MemoryCache)}if(o)return o.setPrefix(g.isset(i,"prefix",!0)?i.prefix:""),o}}return null},t="prototype",o=(n=y)._,(l=n.MemoryCache=function(){this._cache={}})[t]=Object.create(n.Cache[t]),l.isSupported=function(){return!0},l[t]._cache=null,l[t].dispose=function(){return this._cache=null,n.Cache[t].dispose.call(this)},l[t].supportsSync=function(){return!0},l[t].put=function(e,n,t,i){return this._cache[this.prefix+e]=[o.time()+t,n],"function"==typeof i&&i(null,!0),!0},l[t].get=function(e,n){var t;if(e=!!o.isset(this._cache,this.prefix+e,!0)&&(!(t=this._cache[this.prefix+e])||o.time()>t[0]?(delete this._cache[this.prefix+e],!1):t[1]),"function"!=typeof n)return e;n(null,e)},l[t].remove=function(e,n){e=!!o.isset(this._cache,this.prefix+e)&&(delete this._cache[this.prefix+e],!0);if("function"!=typeof n)return e;n(null,e)},l[t].clear=function(e){if(this.prefix.length)for(key in this._cache)o.isset(this._cache,key)&&0===key.indexOf(this.prefix)&&delete this._cache[key];else this._cache={};if("function"!=typeof e)return!0;e(null,!0)},l[t].gc=function(e,n){e=+e;var t=o.time(),i=this.prefix.length;for(key in this._cache)!o.isset(this._cache,key)||i&&0!==key.indexOf(this.prefix)||this._cache[key][0]<t-e&&delete this._cache[key];if("function"!=typeof n)return!0;n(null,!0)},r="prototype",u="UNICACHE_",c=(i=y)._,(l=i.CookieCache=function(){this._cookie=function(e){for(var n,t,i={},o=0,r=(e=(e||document.cookie||"").split(";")).length;o<r;++o)-1!==(t=e[o]).indexOf("=")&&(t=c.trim(t).split("=",2),n=c.trim(t[0]),t=c.trim(t[1]),0===(n=x(n)).indexOf(u))&&n.length>u.length&&(t=x(t),i[n.slice(u.length)]=c.unserialize(t));return i}()})[r]=Object.create(i.Cache[r]),l.isSupported=function(){return!0},l[r]._cookie=null,l[r].dispose=function(){return this._cookie=null,i.Cache[r].dispose.call(this)},l[r].supportsSync=function(){return!0},l[r].put=function(e,n,t,i){e=this.prefix+e,t=[c.time()+t,n];return this._cookie[e]=t,S({name:e,value:c.serialize(t),expires:t[0]}),"function"==typeof i&&i(null,!0),!0},l[r].get=function(e,n){var t;if(e=!!c.isset(this._cookie,this.prefix+e,!0)&&(!(t=this._cookie[this.prefix+e])||c.time()>t[0]?(delete this._cookie[this.prefix+e],E(this.prefix+e),!1):t[1]),"function"!=typeof n)return e;n(null,e)},l[r].remove=function(e,n){e=!!c.isset(this._cookie,this.prefix+e)&&(delete this._cookie[this.prefix+e],E(this.prefix+e),!0);if("function"!=typeof n)return e;n(null,e)},l[r].clear=function(e){for(var n in this._cookie)!c.isset(this._cookie,n)||this.prefix.length&&0!==n.indexOf(this.prefix)||(delete this._cookie[n],E(n));if("function"!=typeof e)return!0;e(null,!0)},l[r].gc=function(e,n){e=+e;var t=c.time(),i=this.prefix.length;for(key in this._cookie)!c.isset(this._cookie,key)||i&&0!==key.indexOf(this.prefix)||this._cookie[key][0]<t-e&&(delete this._cookie[key],E(key));if("function"!=typeof n)return!0;n(null,!0)},function(e){var n="prototype",r="UNICACHE_",f="UNICACHEEXPIRES_",s=e._,l="undefined"!=typeof window?window:"undefined"!=typeof self?self:this;function a(e){e=l.localStorage.getItem(f+e);return e?parseInt(e,10):null}function p(e){l.localStorage.removeItem(r+e),l.localStorage.removeItem(f+e)}var t=e.LocalStorageCache=function(){};t[n]=Object.create(e.Cache[n]),t.isSupported=function(){var e="localStorage";if(!((e=e||"localStorage")in l))return!1;try{var n="___UNICACHE___";return l[e].setItem(n,n),l[e].getItem(n),l[e].removeItem(n),!0}catch(e){return!1}},t[n].supportsSync=function(){return!0},t[n].put=function(e,n,t,i){var t=[s.time()+t,n];return n=this.prefix+e,e=s.serialize(t),t=t[0],l.localStorage.setItem(r+n,e),l.localStorage.setItem(f+n,+t),"function"==typeof i&&i(null,!0),!0},t[n].get=function(e,n){t=this.prefix+e;var t={data:l.localStorage.getItem(r+t),expires:a(t)},i=s.time(),i=!!t.data&&(t.data=s.unserialize(t.data),!t.data||t.data[0]<i||t.expires<i?(p(this.prefix+e),!1):t.data[1]);if("function"!=typeof n)return i;n(null,i)},t[n].remove=function(e,n){if(p(this.prefix+e),"function"!=typeof n)return!0;n(null,!0)},t[n].clear=function(e){for(var n,t=[],i=0,o=l.localStorage.length;i<o;++i)0!==(n=l.localStorage.key(i)).indexOf(r)||(n=n.slice(r.length),this.prefix.length&&0!==n.indexOf(this.prefix))||t.push(n);if(t.map(function(e){p(e)}),"function"!=typeof e)return!0;e(null,!0)},t[n].gc=function(e,n){e=+e;for(var t,i=s.time(),o=this.prefix.length,r=[],u=0,c=l.localStorage.length;u<c;++u)0!==(t=l.localStorage.key(u)).indexOf(f)||(t=t.slice(f.length),o&&0!==t.indexOf(this.prefix))||a(t)<i-e&&r.push(t);if(r.map(function(e){p(e)}),"function"!=typeof n)return!0;n(null,!0)}}(y),function(e){var n="prototype",r="UNICACHE_",f="UNICACHEEXPIRES_",s=e._,l="undefined"!=typeof window?window:"undefined"!=typeof self?self:this;function a(e){e=l.sessionStorage.getItem(f+e);return e?parseInt(e,10):null}function p(e){l.sessionStorage.removeItem(r+e),l.sessionStorage.removeItem(f+e)}var t=e.SessionStorageCache=function(){};t[n]=Object.create(e.Cache[n]),t.isSupported=function(){var e="sessionStorage";if(!((e=e||"localStorage")in l))return!1;try{var n="___UNICACHE___";return l[e].setItem(n,n),l[e].getItem(n),l[e].removeItem(n),!0}catch(e){return!1}},t[n].supportsSync=function(){return!0},t[n].put=function(e,n,t,i){var t=[s.time()+t,n];return n=this.prefix+e,e=s.serialize(t),t=t[0],l.sessionStorage.setItem(r+n,e),l.sessionStorage.setItem(f+n,+t),"function"==typeof i&&i(null,!0),!0},t[n].get=function(e,n){t=this.prefix+e;var t={data:l.sessionStorage.getItem(r+t),expires:a(t)},i=s.time(),i=!!t.data&&(t.data=s.unserialize(t.data),!t.data||t.data[0]<i||t.expires<i?(p(this.prefix+e),!1):t.data[1]);if("function"!=typeof n)return i;n(null,i)},t[n].remove=function(e,n){if(p(this.prefix+e),"function"!=typeof n)return!0;n(null,!0)},t[n].clear=function(e){for(var n,t=[],i=0,o=l.sessionStorage.length;i<o;++i)0!==(n=l.sessionStorage.key(i)).indexOf(r)||(n=n.slice(r.length),this.prefix.length&&0!==n.indexOf(this.prefix))||t.push(n);if(t.map(function(e){p(e)}),"function"!=typeof e)return!0;e(null,!0)},t[n].gc=function(e,n){e=+e;for(var t,i=s.time(),o=this.prefix.length,r=[],u=0,c=l.sessionStorage.length;u<c;++u)0!==(t=l.sessionStorage.key(u)).indexOf(f)||(t=t.slice(f.length),o&&0!==t.indexOf(this.prefix))||a(t)<i-e&&r.push(t);if(r.map(function(e){p(e)}),"function"!=typeof n)return!0;n(null,!0)}}(y),s="prototype",p="unicache_",h=(f=y)._,(l=f.WebSqlCache=function(){this.queue=[]})[s]=Object.create(f.Cache[s]),l.isSupported=function(){return"function"==typeof openDatabase},l[s].db=null,l[s].err=null,l[s].queue=null,l[s].open=function(e){var n,t=this;if(null==t.db){"function"==typeof e&&t.queue.push(e);try{t.db=openDatabase("unicache_websql_db","1.0","UNICACHE Cache Database",2097152)}catch(e){t.err=e,t.db=!1}t.db?t.db.transaction(function(e){v(e,'CREATE TABLE IF NOT EXISTS "'+p+t.prefix+'" (id INTEGER PRIMARY KEY, key unique, value, expires INTEGER)',[],function(e,n){e&&(t.err=e);e=t.queue;t.queue=null,e.map(function(e){e(t.err,t.db)})})},function(e){t.err=e;e=t.queue;t.queue=null,e.map(function(e){e(t.err,t.db)})}):(n=t.queue,t.queue=null,n.map(function(e){e(t.err,t.db)}))}else t.queue?"function"==typeof e&&t.queue.push(e):"function"==typeof e&&e(t.err,t.db);return this},l[s].close=function(){return this.db&&(this.db=null),this},l[s].drop=function(t,i){this.db&&(null==t&&(t=this.prefix),this.open(function(e,n){e?"function"==typeof i&&i(e,null):n.transaction(function(e){v(e,'DROP TABLE IF EXISTS "'+p+t+'"',[],function(e,n){"function"==typeof i&&i(e,n)})},function(e){"function"==typeof i&&i(e,null)})}))},l[s].dispose=function(){return this.close(),this.db=null,this.err=null,this.queue=null,f.Cache[s].dispose.call(this)},l[s].put=function(t,f,s,l){var a=this;a.open(function(e,n){var i,o,r,u,c;e?"function"==typeof l&&l(e,null):(s=+s,e=n,i=a.prefix,o=t,r=h.serialize(f),u=h.time()+s,c=l,e.transaction(function(t){v(t,'SELECT * FROM "'+p+i+'" WHERE key=? LIMIT 1',[o],function(e,n){e?"function"==typeof c&&c(e,null):n&&n.rows.length?v(t,'UPDATE "'+p+i+'" SET value=?,expires=? WHERE key=?',[r,+u,o],function(e,n){"function"==typeof c&&c(e,n)}):v(t,'INSERT INTO "'+p+i+'" (key,value,expires) VALUES(?,?,?)',[o,r,+u],function(e,n){"function"==typeof c&&c(e,n)})})},function(e){"function"==typeof c&&c(e,null)}))})},l[s].get=function(c,f){var s=this;s.open(function(e,t){var i,n,o,r,u;e?"function"==typeof f&&f(e,null):(i=h.time(),n=s.prefix,o=c,r=i,u=function(e,n){e?"function"==typeof f&&f(e,null):(n&&n.expires<i&&I(t,s.prefix,c),"function"==typeof f&&(!n||n.expires<i?f(null,!1):f(null,h.unserialize(n.value))))},t.transaction(function(e){null==r?v(e,'SELECT * FROM "'+p+n+'" WHERE key = ?',[o],function(e,n){"function"==typeof u&&u(e,n&&n.rows.length?{value:n.rows.item(0).value,expires:n.rows.item(0).expires}:null)}):v(e,'SELECT * FROM "'+p+n+'" WHERE key = ? AND expires >= ?',[o,+r],function(e,n){"function"==typeof u&&u(e,n&&n.rows.length?{value:n.rows.item(0).value,expires:n.rows.item(0).expires}:null)})},function(e){"function"==typeof u&&u(e,null)}))})},l[s].remove=function(t,i){var o=this;o.open(function(e,n){e?"function"==typeof i&&i(e,null):I(n,o.prefix,t,i)})},l[s].clear=function(o){var r=this;r.open(function(e,n){var t,i;e?"function"==typeof o&&o(e,null):(t=r.prefix,i=o,n.transaction(function(e){v(e,'DELETE FROM "'+p+t+'"',[],function(e,n){"function"==typeof i&&i(e,n)})},function(e){"function"==typeof i&&i(e,null)}))})},l[s].gc=function(u,c){var f=this;f.open(function(e,n){var t,i,o,r;e?"function"==typeof c&&c(e,null):(u=+u,e=h.time(),n=n,t=f.prefix,i=u,r=c,null==(o=e)&&(o=h.time()),n.transaction(function(e){v(e,'DELETE FROM "'+p+t+'" WHERE expires < ?',[o-i],function(e,n){"function"==typeof r&&r(e,n)})},function(e){"function"==typeof r&&r(e,null)}))})},function(e){var n="prototype",a=e._,p="unicache_db_store_",t="undefined"!=typeof window?window:"undefined"!=typeof self?self:this,o=function(){var e={db:null,transaction:{READ_WRITE:"readwrite"},keyrange:null};try{void 0!==t.indexedDB?e.db=t.indexedDB:void 0!==t.webkitIndexedDB?e.db=t.webkitIndexedDB:void 0!==t.mozIndexedDB?e.db=t.mozIndexedDB:void 0!==t.OIndexedDB?e.db=t.OIndexedDB:void 0!==t.msIndexedDB&&(e.db=t.msIndexedDB)}catch(e){}try{void 0!==t.IDBTransaction?e.transaction=t.IDBTransaction:void 0!==t.webkitIDBTransaction?e.transaction=t.webkitIDBTransaction:void 0!==t.msIDBTransaction&&(e.transaction=t.msIDBTransaction)}catch(e){}try{void 0!==t.IDBKeyRange?e.keyrange=t.IDBKeyRange:void 0!==t.webkitIDBKeyRange?e.keyrange=t.webkitIDBKeyRange:void 0!==t.msIDBKeyRange&&(e.keyrange=t.msIDBKeyRange)}catch(e){}return e}();var i=e.IndexedDbCache=function(){this.queue=[]};function f(e,n,t,i){e=e.transaction([n],"readwrite").objectStore(n).delete(t);e.onerror=function(e){"function"==typeof i&&i(new Error('Deleting "'+t+'" failed!'),null)},e.onsuccess=function(e){"function"==typeof i&&i(null,!0)}}i[n]=Object.create(e.Cache[n]),i.isSupported=function(){return!!o.db},i[n].request=null,i[n].db=null,i[n].queue=null,i[n].open=function(e){var i=this;return i.request?null==i.db?i.queue&&"function"==typeof e&&i.queue.push(e):!1===i.db?"function"==typeof e&&e(new Error("IndexedDB cannot be opened"),null):i.db&&"function"==typeof e&&e(null,i.db):(i.queue&&"function"==typeof e&&i.queue.push(e),i.request=o.db.open("unicache-indexeddb-cache-db",1),i.request.onerror=function(e){var n,t;i.db=!1,i.queue&&(n=new Error("IndexedDB Open Error with code "+i.request.errorCode),t=i.queue,i.queue=null,t.map(function(e){e(n,null)}))},i.request.onblocked=function(e){console.warn("UNICACHE: Please close all other tabs with this site open!")},i.request.onupgradeneeded=function(e){e.target.result.createObjectStore(p+i.prefix)},i.request.onsuccess=function(e){i.db=e.target.result,i.db.onclose=function(e){i.db=null},i.db.onversionchange=function(e){i.db.close(),i.db=null},i.queue&&(e=i.queue,i.queue=null,e.map(function(e){e(null,i.db)}))}),this},i[n].close=function(){return this.db&&(this.db.close(),this.db=null),this},i[n].dispose=function(){return this.close(),this.db=null,this.request=null,this.queue=null,e.Cache[n].dispose.call(this)},i[n].supportsSync=function(){return!1},i[n].put=function(u,c,f,s){var l=this;l.open(function(e,n){var t,i,o,r;e?"function"==typeof s&&s(e,null):(e=n,n=p+l.prefix,t=u,i=c,o=+f,r=function(e,n){"function"==typeof s&&s(e,n)},(e=e.transaction([n],"readwrite").objectStore(n).put([a.time()+o,i],t)).onerror=function(e){"function"==typeof r&&r(new Error('Setting "'+t+'" failed!'),null)},e.onsuccess=function(e){"function"==typeof r&&r(null,!0)})})},i[n].get=function(r,u){var c=this;c.open(function(e,t){var n,i,o;e?"function"==typeof u&&u(e,null):(e=p+c.prefix,n=r,i=function(e,n){"function"==typeof u?e?u(e,null):n?n[0]<a.time()?(f(t,p+c.prefix,r),u(null,!1)):u(null,n[1]):u(null,!1):!e&&n&&n[0]<a.time()&&f(t,p+c.prefix,r)},(o=t.transaction([e],"readonly").objectStore(e).get(n)).onerror=function(e){"function"==typeof i&&i(new Error('Retrieving "'+n+'" failed!'),null)},o.onsuccess=function(e){"function"==typeof i&&i(null,o.result)})})},i[n].remove=function(t,i){var o=this;o.open(function(e,n){e?"function"==typeof i&&i(e,null):f(n,p+o.prefix,t,function(e,n){"function"==typeof i&&i(e,n)})})},i[n].clear=function(t){var i=this;i.open(function(e,n){e?"function"==typeof t&&t(e,null):((e=n.transaction(p+i.prefix,"readwrite").objectStore(p+i.prefix).clear()).onerror=function(e){"function"==typeof t&&t(new Error("Error clearing store "+e.target.errorCode),null)},e.onsuccess=function(e){"function"==typeof t&&t(null,!0)})})},i[n].gc=function(i,o){i=+i;var r=a.time(),u=this;u.open(function(e,n){var t;e?"function"==typeof o&&o(e,null):(e=n.transaction(p+u.prefix,"readwrite").objectStore(p+u.prefix).openCursor(),t=[],e.onerror=function(e){"function"==typeof o&&o(new Error("Error looping through store "+e.target.errorCode),null)},e.onsuccess=function(e){e=e.target.result;e?(e.value[0]<r-i&&t.push(e.key),e.continue()):setTimeout(function(){t.map(function(e){f(n,p+u.prefix,e)}),"function"==typeof o&&o(null,!0)},10)})})}}(y),y});
|