Quiero agregar caché a mi sitio. Estoy usando las siguientes dos funciones para agregar y obtener el caché. Funciona bien durante el desarrollo, pero cuando uso Docker para compilar la aplicación, el almacenamiento en caché no funciona. Me está dando el siguiente error. (DOMException no detectada (en promesa): la operación no es segura).
Aquí está mi código.
export const addDataIntoCache = (cacheName, url, response) => { // Converting our response into Actual Response form const data = new Response(JSON.stringify(response)); if ('caches' in window) { // Opening given cache and putting our data into it caches.open(cacheName).then((cache) => { cache.put(url, data); console.log('Data Added into cache!') }); } else { console.log("does not able to find caches in window"); caches.open(cacheName).then((cache) => { cache.put(url, data); console.log('Data Added into cache!') }); } }; export const getSingleCacheData = async (cacheName, url) => { if (typeof caches === 'undefined') { console.log("cache is undefined"); return null; } const cacheStorage = await caches.open(cacheName); const cachedResponse = await cacheStorage.match(url); // If no cache exists if (!cachedResponse || !cachedResponse.ok) { console.log('Fetched failed!'); return null; } return cachedResponse.json().then((item) => { console.log("fetched from cache"); console.log(item); return item; }); };