简体   繁体   中英

Loading data from DB for caching using ehcache and spring to override exisitng caching mechanism

I am working on performance improvement of my project (Spring Project,I don't have much experience in spring, around 7 months!), where we found that most of the memory is being utilized while caching. After a few R&D, I found that Ehcache might help me. In my project we have used static HashMap to load the data from DB on the server start and we are using this map throughout the application. I did see a few example of Ecache and Spring (NOT spring boot) but I am unable to understand how do I replace it with my existing code where there are HashMaps everywhere? Also if there is any other advice or suggestion, please post it..I will be of great help..! there are a few links on stackoverflow about same question, but they don't have answers for them.. Please help..!

If you have the data in a HashMap and now you want to use a EHCache, the access time for one entry, if this entry is inside the cache already, will be more then 10x higher of what you have now. See "Runtime comparison for hit hits" at In Process Java Cache Benchmarks .

If you want to save on memory, access times will get much higher, since you have to reload data, when it is requested.

If your application operates on the HashMap and does not need any access to the DB after the HashMaps are loaded, you actually have already the perfect custom cache tailored for your application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM