From ccd53c0734f2e57784d868089b95df94c43b1d23 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 2 Nov 2018 10:06:20 +0000 Subject: [PATCH] improved compression --- dist/cache-api-keyval.js | 8 ++++---- src/cache-api-keyval.js | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/dist/cache-api-keyval.js b/dist/cache-api-keyval.js index 4c97faa..4a792d7 100644 --- a/dist/cache-api-keyval.js +++ b/dist/cache-api-keyval.js @@ -1,4 +1,4 @@ -(function(g){var c="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this;caches instanceof CacheStorage?c.CacheApiDB=g():(console&&console.error("Browser does not support Cache API"),c.CacheApiDB=c.c?c.c():function(){var c=this;c.supported=0;["get","set","del","prune"].forEach(function(e){c[e]=function(){return Promise.reject("Browser does not support Cache API")}})})})(function(){function g(a,b){return caches.open(a).then(function(d){var a=new Request((b|| -"").toString());return d.match(a).then(function(b){var a;(a=!b)||((a=b.headers.get("x-expire"))&&b.headers.get("x-date")+ac)throw Error("Expire time not numeric");f["x-expire"]=c.toString()}f=new Response(d,{headers:f});return a.put(e,f)})}function h(){var a=key;caches.open(store).then(function(b){var c=new Request((a||"").toString());return b["delete"](c)})}function e(a,b){if(this instanceof e)this.b=a,this.supported=1,"object"==typeof b&&b.namespace&&(this.a=b.namespace);else return new e(a,b)}e.prototype.get=function(a){var b=this.a;return g(this.b,(b?b+":":"")+a)}; -e.prototype.set=function(a,b){var d=this.a;return c(this.b,(d?d+":":"")+a,b)};return e}); +(function(d){var c="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this;caches instanceof CacheStorage?c.CacheApiDB=d():(console&&console.error("Browser does not support Cache API"),c.CacheApiDB=c.c?c.c():function(){var c=this;c.supported=0;["get","set","del","prune"].forEach(function(d){c[d]=function(){return Promise.reject("Browser does not support Cache API")}})})})(function(){function d(a,b){return caches.open(a).then(b)}function c(a,b){return d(a, +function(a){var e=new Request((b||"").toString());return a.match(e).then(function(b){var a;(a=!b)||((a=b.headers.get("x-expire"))&&b.headers.get("x-date")+ac)throw Error("Expire time not numeric");f["x-expire"]=c.toString()}f=new Response(e,{headers:f});return a.put(d,f)})}function k(){var a=key;d(store,function(b){var c=new Request((a||"").toString());return b["delete"](c)})}function g(a,b){if(this instanceof g)this.b=a,this.supported=1,"object"==typeof b&&b.namespace&&(this.a=b.namespace);else return new g(a,b)}g.prototype.get=function(a){var b=this.a;return c(this.b,(b?b+":":"")+a)}; +g.prototype.set=function(a,b){var c=this.a;return h(this.b,(c?c+":":"")+a,b)};return g}); diff --git a/src/cache-api-keyval.js b/src/cache-api-keyval.js index 9a937cb..7b21fe6 100644 --- a/src/cache-api-keyval.js +++ b/src/cache-api-keyval.js @@ -40,8 +40,8 @@ } // open cache storage - function CACHE_OPEN(store) { - return caches.open(store); + function CACHE_OPEN(store, callback) { + return caches.open(store).then(callback); } // return cache key @@ -51,7 +51,7 @@ // get key from cache function CACHE_GET(store, key) { - return CACHE_OPEN(store).then(function(cache) { + return CACHE_OPEN(store, function(cache) { var cache_key = CACHE_KEY(key); @@ -73,7 +73,7 @@ // set key in cache function CACHE_SET(store, key, data, expire) { - return CACHE_OPEN(store).then(function(cache) { + return CACHE_OPEN(store, function(cache) { var cache_key = CACHE_KEY(key); @@ -82,8 +82,8 @@ // cache date cache_headers[DATE_HEADER] = NOW(); - // content type - if (typeof data === 'object') { + // JSON content type + if (IS_OBJECT(data)) { // JSON cache_headers[CONTENT_TYPE_HEADER] = CONTENT_TYPE_JSON; @@ -129,7 +129,7 @@ // set key in cache function CACHE_DELETE(store, key) { - return CACHE_OPEN(store).then(function(cache) { + return CACHE_OPEN(store, function(cache) { var cache_key = CACHE_KEY(key); return cache.delete(cache_key); }); @@ -137,7 +137,7 @@ // set key in cache function CACHE_PRUNE(store, key) { - return CACHE_OPEN(store).then(function(cache) { + return CACHE_OPEN(store, function(cache) { // get all keys from store return cache.keys().then(function(keys) {