mongodb - express做的文章管理网站,文章分类查询问题,如何实现只查询一次数据库?
淡淡烟草味
淡淡烟草味 2017-04-26 09:01:39
0
6
705

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

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

数据库用的 MongoDB

工具用的 mongoose

淡淡烟草味
淡淡烟草味

reply all(6)
巴扎黑

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

迷茫

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

刘奇

Split the page and introduce additional ejs subpages.

Ty80

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

大家讲道理

You can save it in cache

洪涛

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!