java - Global Variables in spring mvc -


i have created spring mvc web application. menus database i.e stored in databases. whenever call index.jsp home page different browser, menu items retrieved every time database. how can stored menu items in global variable can accessed anytime without hitting database again or until restart server.

you requirement can sufficed in 2 ways:

  1. server cache:
    use open source server cache library ehcache lets store data (you app data or data retrieved database or data received 3rd party app call) in server memory. idea instead of performing same 3rd party call expected give same result, once , store in server cache.
    ehcache works spring framework, , in fact use ehcache server side caching our enterprise application based on spring framework.

  2. browser database storage:
    html5 provide indexeddb api lets store data in browser database.
    so, can retrieve data server once , store in local database, whenever need data can first check if present in local database or not, if not retrieve , store in local db, else fetch local db.
    advantage of approach you can save server call, lesser network traffic.

depending on requirement, can choose 1 option.

i not recommend storing data, retrieved database, in global variables. not scalable approach.

you can find plenty of online tutorials, 1 suggest in each case:


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -