title: Designing Cache Server using LFU to decrease Database Load
body: <p>I am trying to design a Cache Server, that will store the Query and Result key for DB Queries, thus putting less load on it.<br>
  It might be something like :<br></p>
  
  <pre><code>if Cache.isSet(query):
         return Cache.get(query)
  else:
         result = db.run(query)
         Cache.set(query, result)
         return result
  </code></pre>
  
  <p>Properties of Cache I am planning to design:<br></p>
  
  <ul>
  <li>Will be a Cache Server, using REST API</li>
  <li>Will use Hashmap to Store in Key-Value form in RAM</li>
  <li>The Hashmap will be backuped (serialization to a file at intervals)</li>
  </ul>
  
  <p>I am trying to make this Cache for an URL Shortener, but want to expand this as a full fledged Cache Server. 
  The Issues I am facing are:</p>
  
  <ul>
  <li>How will I determine the number of Key-Value Pairs to be stored?</li>
  <li>If the value in DB is changed, will I have to remove the Query(Key) that deals with it?</li>
  </ul>
  
  <p>How do I solve this?</p>