Something went wrong. Try again.
Mirror of https://github.com/improsocial/improAn extensible Bluesky client for web
Something went wrong. Try again.
JavaScript
1234567891011121314151617181920212223242526272829303132333435363738394041const CACHE_NAME = "plugins-v1";
// Responses are cached indefinitely until cleared// URLs are versioned so new versions should fetch new entries
export class PluginCache { async _getCache() { return await caches.open(CACHE_NAME); }
async fetch(url, { doCacheNotFound = false } = {}) { const cache = await this._getCache(); let response = await cache.match(url); if (!response) { response = await fetch(url, { redirect: "follow" }); if (response.ok || (doCacheNotFound && response.status === 404)) { await cache.put(url, response.clone()); } } if (!response.ok) { const error = new Error(`HTTP ${response.status} ${url}`); error.status = response.status; error.body = await response.text().catch(() => null); throw error; } return response; }
async reconcile(wantedUrls) { // Clear unwanted urls const cache = await this._getCache(); const wanted = new Set(wantedUrls); const keys = await cache.keys(); await Promise.all( keys .filter((request) => !wanted.has(request.url)) .map((request) => cache.delete(request)), ); }}