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

170
Visualizações
await have to execute chained method one is async(.find) and other is sync (.cahe()) so but cache (second method is executed first) then find?

In overview function we called await Tour.find().cache() so find should be called first then cache but the first acutally cache is executed first then find method ? Is this because await is executing sync and async function it first exeution sync then async (yes without escaping to next line of code ) or it is something else

Here is handler function (Overview.js) exports.getOverview = catchAsync(async (req, res, next) => {

Can you explain why this is not executing the way I think? const tours = await Tour.find().cache(); res.status(200).render("overview", { title: "All Tours", tours, }); });

Here is function defined in exec.js const { exec } = mongoose.Query.prototype;

    mongoose.Query.prototype.cache = function () {
      this.useCache = true;
      return this;
    };
    
    
    mongoose.Query.prototype.exec = async function () {
      
      if (!this.useCache) return exec.apply(this, arguments);
    
      
      const key = JSON.stringify(
        Object.assign({}, this.getQuery(), {
          collection: this.mongooseCollection.name,
        })
      );
    
      
      const cacheValue = await client.get(key);
    
    
      if (cacheValue) {
        const doc = JSON.parse(cacheValue);
        return Array.isArray(doc) ? doc.map((d) => this.model(d)) : this.model(doc);
      }
    
      // if we do, return that
    
      // Otherwise, issue the query and store the result in redis
    
      const result = await exec.apply(this, arguments);
    
      client.set(key, JSON.stringify(result), "Ex", 10);
    
      return result;
    };
    
                    
                   
about 4 years ago · Juan Pablo Isaza
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