title: Keeping data in memory,  Design approach
body: <p>I have a problem where in I need to process some files with size in the range of few kbs up to 1 GB max. The use case is such that the input is in some flat file format where the data is stored in a single line, say some payment instructions. Application has to go through each payment instruction and form groups based on some grouping logic. At the end the groups has to be converted to another format(ISO 20022 xml) using which payment processing will be happening.</p>
  
  <p>The current design is such that, we have two tables where grouping criteria data is stored in one table and  individual payment instruction is stored in another table (One to Many relationship from group Table to Payment Instruction Table). And in Step 1 : as and when we go through the flat file we identify the group it belongs to, and write to the database(bulk commit btw). </p>
  
  <p>In step 2: of batch processing the groups are read one by one and form the output xml and send to the destination.</p>
  
  <p>The issue I'm facing now is that writing to two tables and fetching from that is an overkill, if the entire thing can be done in memory.</p>
  
  <p>I'm thinking of an approach where in I can keep a HashTable(google guava (<a href="http://code.google.com/p/guava-libraries/" rel="nofollow">MapMaker</a>)) kind of caching, and the size of which I can specify,  and once the cache reaches the upper limit I can write them into database tables (weave an aspect on the put to cache).</p>
  
  <p>In the same way while retrieving the entries I can first check in the cache for the key and if it not there,  query the database.</p>
  
  <p>What is your opinion on this design approach(Is it another blunder or something which I can make practical and at the same time stable, and can scale).</p>
  
  <p>Why I thought of this is, we don't have big files coming in always,  and we require these temperory tables only if we cannot process the entire file in memory and may lead to OutOfMemory problems.</p>
  
  <p>Could you please give some suggestions ?</p>
  
  <p>Thanks</p>