Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

167
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda