Hi,
I've looked around in forums and the HIA book without luck. I'm wondering if it is possible to only cache a query given a set of conditions, for example, only if the result set is not empty. What I would expect HB to do would be to:
for a given a query Q:
lookup Q's result set in cache region
if result set exists, return that result set
otherwise, run Q and get result set
ONLY cache result set if certain condition applies (eg result set not empty)
The "not empty" case would be very handy for a "find or create" method that runs (expensive) Q to find an instance of a mapped class C. if the instance is not found, the method inserts a new instance of C. I would like HB to cache Q only if an instance of C was found. Otherwise, the 2nd time "find or create" is run, if the cached (empty) result set is used, the method will incorrectly try to insert a new instance of C...
For this example, I do understand that the default query cache factory would nuke every cached query that depends on C after the insert (including the cached result for Q when it found no results), but in my particular app, I've extended the default query cache factory to be "stale tolerant", so that cached queries are still used within a configurable amount of time after they've been deemed stale...
|