'use strict'; const { openDB } = require('idb'); class BrowserCache { constructor() { this._db = openDB('yt-cache', 1, { upgrade(db) { db.createObjectStore('cache'); } }); } /** * * @param {string} key * @returns {Promise} */ async read(key) { const data = await (await this._db).get('cache', key); return data; } /** * * @param {string} key * @param {ArrayBuffer} data * @returns {Promise} */ async write(key, data) { await (await this._db).put('cache', data, key); } /** * * @param {string} key * @returns {Promise} */ async exists(key) { const data = await (await this._db).get('cache', key); return data !== undefined; } /** * * @param {string} key * @returns {Promise} */ async remove(key) { await (await this._db).delete('cache', key); } } module.exports = new BrowserCache();