Thread: cache in spring

Forum : Spring Core and Aspect Oriented Programming (AOP).   14 May, 2018 16:33
User Image


Joined: 2 Apr, 2018

Points: 100

Threads: 2

Posts: 0

Answer Icon cache in spring

| Quote Date : 14 May, 2018    Views:390    

why cache store data in key-value pair is it possible to store any otherway?


User Image


Joined : 8 Mar, 2018

Points : 110

Threads: 1

Posts: 2

Answer IconRe: cache in spring

Reply Date : 16 May, 2018

First of let me tell why cache? In db or any storage media like properties file or anything, if it have some data and that is not going to modified by the user as part of the application usage and such data we are reading frequently to achieve the requirement. Then unnecessarily by reading again and again we are consuming the cpu time so as part of that our application performance will be degraded and if any modification needed means then its going to create a severe maintenance problem for us.

So here the ideal solution will be to read the data only once and store it somewhere . so that other components of our application can use this stored data. If we will store with in the request or session scope then such data can be accessed only by the web application component. so if we want that our stored data should get accessible to all the components of our application i.e even a pojo class also. Then thats where cache comes into picture.

As there will be multiple master data like city , state, country, banks and so on so for easy identification of all those data if we should go for map which allows to store in key value approach then we can easily retrieve the data and can start using those. Due to the easy identification of our required data among large amount of various types of data, its highly recommended to use Map as a storage area within the cache.

 hopes you have got some idea. 
Thank you
Milan kumar

User Image


Joined : 8 May, 2017

Points : 230

Threads: 57

Posts: 216

Re: cache in spring

Reply Date : 15 May, 2018

generally we used to store data in file or database or properties file. These all are parmanent storage , but we want tempory storage so best is hashmap where key and values we can store. No need to write any logic. We can also store in arraylist but while retriving we will get only values no reference but in Map with reference key with value. 

Load More

No More Comments