title: How to handle SQL query result caching
body: <p>In a Perl program I cache SQL request result to speed up the program.<br /></p>
  
  <p>I see two common way to do that:</p>
  
  <ul>
  <li>Create a hash using the query as index to cache result, like suggested <a href="https://stackoverflow.com/questions/757110/is-there-a-way-to-caching-mechanism-for-classdbi/1518501#1518501">here</a></li>
  <li>Create a hash with but 2 index, first is the list of used table, second is where clause</li>
  </ul>
  
  <p>I today used the 2nd option because it's easier to clean the cache for a given set of table when you know they have been changed.<br /></p>
  
  <p>My problem is to handle the cache cleaning, today most select query I do are against table with very few change. So when I run an update/delete/... I just clean up the hash table part that cache result for this table.</p>
  
  <p>This has few impact on performance as I rarely have to clean the part of the hash that is often used.<br />
  But now for a program with more often update/delete on most table, this make my cache much less efficient as I often have to clean it.</p>
  
  <p>How to deal with that ? My current cache system is quite simple, Cache::Memcached::Fast is quite complex. Do you have a solution that would be more efficient that mine but still quite simple ?</p>