ECM
ECM
总版主
总版主
  • 社区居民
  • 忠实会员
  • 原创写手
阅读:776回复:0

Global Variables in spring mvc [closed]

楼主#
更多 发布于:2016-05-12 14:42
I have created a spring mvc web application. My menus are database i.e they are stored in the databases. Whenever I call index.jsp which is my home page from a different browser, the menu items are retrieved every time from database. How can I stored the menu items in a global variable which can be accessed anytime without hitting the database again or until I restart the server.You requirement can be sufficed in 2 ways: Server cache: Use some open source server cache library like ehcache which lets you store data (you app data or data retrieved from database or data received from some 3rd party app call) in server memory. Idea is that instead of performing same 3rd party call which is expected to give same result, do it once and then store it in server cache. Ehcache works well with Spring framework, and in fact we use ehcache for server side caching for our enterprise application which is based on Spring framework. Browser database storage: HTML5 provide IndexedDB API which lets you store data in browser database. So, you can retrieve the data from server once and then store it in local database, then whenever you need data you can first check if it is present in local database or not, if not then retrieve and store in local db, else fetch from local db. Advantage of this approach is that you can save even the server call, so lesser network traffic. Depending on you requirement, you can choose one option. I would NOT recommend storing data, which is retrieved from database, in global variables. It is really not a scalable approach. You can find plenty of online tutorials, but 1 would suggest in each case: ehcache IndexedDB

 

 

 

 

 

 

 

异常中心网是一家专门收集整理程序员编程过程中遇到的常见异常(exception)以及各种异常问答中心的网站。异常中心网旨在,减少程序员在编码遇到异常,处理各种异常时间和痛苦,让程序员能更愉快的、快速的定位异常并查找对应的异常解决方案。异常中心网诚心打造最完美的编程社区为程序员用户服务,努力成为最好的程序员乐园程序员社区程序异常中心程序bug中心异常问答中心

 

喜欢0 评分0
游客

返回顶部