Caching database queries can reduce and even remove the performance degradation caused by slow database access. I have just finished an article that discusses steps needed to address the performance problem caused by the heavy database queries such as optimizing and caching database queries and provides code examples.
One thing to keep in mind that a plain query cache usually should be bigger than an entity cache because the variability is higher (query text plus parameters).
A more advanced approach is a Cache of Caches Pattern. The fist (or front) cache using the SQL query text as a key holds second-level caches. The second-level caches hold actual query results for a given parameter set:
Here, the queries executed more often have a better chance of avoiding eviction. Upon eviction from the front cache the query result cache should be destroyed.
If cache look up speed is of utmost importance, distributing the query cache among a bunch of machines may be a better option.
Regards,
Slava Imeshev
August 1, 2008
» Caching Database Queries in Java






