Out of curiosity, why do you suggest the L2C check should happen optionally?
I'm actually not sure I remember why. That's how Emmanuel Bernard coded it in Hibernate Search, so to port the implementation maintaining the option we'd need that, but if nobody remembers why that could be important I'd be happy to drop the option and make it implicitly enabled.
I suspect the reason is that when the chance of hitting the cache is quite low, one ends up doing multiple lookups in the 2lc cache, which might be expensive, and then still need to perform a SQL load anyway for the missing entries. I guess that loading 10 entities from DB rather than 8 doesn't make a big difference, so it might be useful to "hint" against using the 2lc for this.
I'm not sure if 2lc should be disabled by default, or if maybe Hibernate ORM could use some smarter stats to figure out which strategy is best automatically.
|