UNPKG

fake-service-worker

Version:

Fake service worker implementation for testing developer edge applications

48 lines 1.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EdgeCacheStorage = void 0; const Cache_1 = require("./Cache"); class EdgeCacheStorage { /** Default global cache */ default; caches; constructor() { this.default = new Cache_1.EdgeCache(); this.caches = {}; this.caches['default'] = this.default; } /** Delete a custom cache */ async delete(cacheName) { if (!this.caches[cacheName]) return false; delete this.caches[cacheName]; return true; } /** Check a cache exists */ async has(cacheName) { return !!this.caches[cacheName]; } /** Returns array of cache names */ async keys() { return Object.keys(this.caches); } /** Checks for a match in all caches.*/ async match(request, options) { let match = undefined; const keys = Object.keys(this.caches); for (let i = 0; i < keys.length; i++) { const key = keys[i]; match = await this.caches[key].match(request); if (match) break; } return match; } /** Create a cache with cachename */ async open(cacheName) { this.caches[cacheName] = new Cache_1.EdgeCache(); return this.caches[cacheName]; } } exports.EdgeCacheStorage = EdgeCacheStorage; //# sourceMappingURL=CacheStorage.js.map