• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Data cashing

 
Greenhorn
Posts: 28
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wrote a service to lookup for a code in the database.
to minimize the database i/o i implemented my own caching in my service.
The service first looks for the code in the Maps and ArrayList and if it doesn’t exist then it queries the database and adds the new data to the map so that the next similar requests can find the data in the Maps and ArrayList.

I can have 100s of conditions and each condition can have 100s of groups. Each group has 1000s of codes in an ArrayList.



With this approach I am afraid that I may run into out of memory issue when we accumulate lot conditions, groups and codes.

What would be the best solutions?

Thanks
Aadil
 
Marshal
Posts: 5475
326
IntelliJ IDE Python Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I recommend using an off the shelf caching solution such as ehcache. Trying to roll your own cache is a terrible idea, and you've only just scratched the surface of the pain you're in for if you try.
 
Saloon Keeper
Posts: 26300
187
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Aadil Shaik wrote:
With this approach I am afraid that I may run into out of memory issue when we accumulate lot conditions, groups and codes.



Oracle wasn't. I spent a month of my professional life running and re-running a massive multi-hour app that ran out of memory before I learned that. It was documented, actually, but not where or how you'd expect to find that information. I more or less had to work back from the post-mortem object dumps.

Most of us had been taught that a cache should be a finite resource where once filled, some sort of algorithm would be used to purge less-desirable items and make space for new ones. Typically, it's either a simple first-in/first-out or a Least Recently Used (LRU) algorithm. Not this particular driver, however.

Regardless, unless you're purely into it for the academic experience, take Mr. Cooke's advice. Use one of the pre-existing (and pre-debugged!) cache managers and don't waste time rolling your own. Even if you don't use a full-blown external cache, there are cache libraries around (look in the Apache.org java resources, for example).
 
I love a good mentalist. And so does this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic