search

Home  >  Q&A  >  body text

mongodb - express做的文章管理网站,文章分类查询问题,如何实现只查询一次数据库?

express写的文章管理系统,每个页面的菜单导航栏都是一样的,但是每个页面都从数据库去查询了一次所有的菜单。

怎么使整个网站只从数据库查询一次菜单,然后把数据给每个页面使用呢?

数据库用的 MongoDB

工具用的 mongoose

淡淡烟草味淡淡烟草味2865 days ago788

reply all(6)I'll reply

  • 巴扎黑

    巴扎黑2017-04-26 09:03:39

    I don’t knownode, is it possible to load the menu data when it is started and put the menu data into global variables?

    reply
    0
  • 迷茫

    迷茫2017-04-26 09:03:39

    Personally, I think you can do a layer of caching.

    reply
    0
  • 怪我咯

    怪我咯2017-04-26 09:03:39

    Split the page and introduce additional ejs subpages.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-26 09:03:39

    https://github.com/hubwiz/example-node

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-26 09:03:39

    You can save it in cache

    reply
    0
  • PHP中文网

    PHP中文网2017-04-26 09:03:39

    Cache, is it useful for redis?
    Or you bind it to app.locals, check it, if there is a menu, just get it directly, if not, go to the database to query and bind it.
    In this way, you can get it directly every time. Of course, if you update, the menu should also be updated on app.locals.

    reply
    0
  • Cancelreply