Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

214
Visualizações
Access to body response on Cache with Javascript

I'm working on a node.js and i want to store some data on cache.

The request is stored successfully.

const version = "3.4.3";
caches.open('v' + version)
.then(async cache => {
    await cache.add('/getTranslations');
    const data = await cache.match('/getTranslations');
});

Here is what endpoint returns:

app.get("/getTranslations", (req, res) => {
            res.status(200).send(/*Here is the object shown 
            on the next picture and what i want to read from cache*/);
});

I have this on cache on chrome: Chache

I'm trying to access to what is show on the preview but I'm not able to get it.

Using

// In my case the name of the cache is 'v4'
const c = await caches.open('v4');

// Here finds the 7 requests.
await c.keys()

// Here i get the request but i can't not get the data I'm looking for.
await c.match('/getTranslations')
about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

Here i found the solution myself with javascript: Using as an example what is shown on the question request would be '/getTranslations' and version would be '4'.

cachePetition: async function (version: string, request: string) {
        let body = -1;
        return caches.open('v' + version).then(async cache => {
            // Function to get the cached data
            const writeRequestToCache = async () => {
                console.log("[Cache] Getting '" + request + "' ...");
                await cache.add(request);
                const result = await cache.match(request);
                return result.json();
            }

            let data = await cache.match(request);

            // If there is no data in the cache, get it from the server
            if (data == undefined) {
                console.log("[Cache] '" + request + "' not found.");
                body = await writeRequestToCache();
            } else {
                body = await data.json();
                // If you can't access to the body of the petition ask it again. This is a workaround for the cache bug.
                if (body == undefined) {
                    console.log("[Cache] '" + request + "' data corrupted. Getting it again...");
                    body = await writeRequestToCache();
                } else {
                    console.log("[Cache] '" + request + "' found.");
                }
            }
            return body;
        });
    }
about 4 years ago · Santiago Gelvez Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda