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
July 18, 2008
» Caching for Java Applications
JavaLobby has published my short article introducing caching for Java. This turned out to be a challenge. Because of the article format requirement, I could only cover very basics. Things such as session-level caching, external cache storages and dealing with full scans had to be left outside. On the other hand, maybe it's a good thing because it kept the article simple. Anyway, that was a long-overdue discussion, and I thank Rick Ross and Nitin Bharti for pushing me to finish it.
The second article will cover scaling Java apps beyond a single box.






