Thread: cache in spring

Forum : Spring Core and Aspect Oriented Programming (AOP).   14-5-2018 12:33:37 PM
User Image
Dinesh14

Newbie

Joined: Apr 2, 2018

Points: 100

Threads: 2

Posts: 0

Answer Icon cache in spring

| Quote Date : May 14, 2018    Views:221    

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

Comments

User Image
MilanKumar

Newbie

Joined : Mar 8, 2018

Points : 110

Threads: 1

Posts: 2

Answer IconRe: cache in spring

Reply Date : May 16, 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
Amritk

Newbie

Joined : May 8, 2017

Points : 230

Threads: 57

Posts: 211

Re: cache in spring

Reply Date : May 15, 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