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

109
Visualizações
Caching select query data on server side

I am writing an express app, where I'm pushing data from my views to a database. But most of the data is mapped to some other data in database tables.

For example, is a choose student name drop down- once you choose the student by his name , a drop down below - will show all roles that he is allowed for.

So I'm following this pattern of

app.post('\action1', function(req,res){
  function querySomething(){
    var defered = Q.defer();
      connection.query(some_select_query,defered.makeNodeResolver());
      return defered.promise;
    }

  function querySomethingElse(){
    var defered = Q.defer();
      connection.query(some_other_select_query,defered.makeNodeResolver());
      return defered.promise;
    }

   Q.all([querySomething(), querySomethingElse()]).then((results,err) => {
       connection.release()
       if(results){
          res.render('some_view.ejs', {
             result1:results[0][0],
             result2:results[1][0]
          });
       }
       else{
         res.render('error.ejs',{});
       }
   })
})

Now the problem is that I have to follow this pattern of selecting something from multiple tables, pass all these function to a promise- and when the results is passed back, goto my view with all those result objects - so that I can use them in my view - as a means of doing drop downs dependent on one another.

Sometimes I have to re-write this multiple times.

Doing a select query like this would be performance intensive especially if all views are using the result of the same query.

Is there any way I can build a cached data store on my express server side code and query that instead of the actual database??

If there is an insert or an update - i will refresh this store and just do a new select * that one time.

What libraries are there on top of express which will help me do this??

Does mysql-cache does the same thing?? I'm also using connection pooling with createPool.

How do I achieve this - or do I just restore to using big mvc's like sails to rewrite my app?

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You can try apiCache npm module.

"Sometimes I have to re-write this multiple times."

Based on the business need, you may want to handle each use case separately and this scenario doesn't deal with caching.

Doing a select query like this would be performance intensive especially if all views are using the result of the same query.

This is a classic example for the need of server-side caching.

about 4 years ago · Santiago Trujillo 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