Hi Scott, Maybe I am not understanding your solution correctly, so I summarize what I understood:
- Monitor all EntityCondition creations from EntityDateFilterCondition,makeCondition or EntityUtil.filterByDate - If the query has a field called "fromDate" then log a warning and disable caching If my above understanding is correct, then isn't that a bit strange? I mean it seems to be quite a specific workaround as opposed to a generic solution. Shouldn't we instead have something that works for all dates instead of just specific dates with the name "fromDate" when compared with current date / time? On Thu, Apr 6, 2017 at 2:10 AM, Scott Gray <scott.g...@hotwaxsystems.com> wrote: > In the current project I'm working on I see a lot of developers making the > mistake of caching date filtered queries. > > Why shouldn't you cache date filtered queries? > 1. If you're filtering by the current moment in time then the results are > irrelevant within a few moments of them being retrieved. Some records may > be due to expire and others (that were filtered out) may be about to become > active. > 2. Despite what I say in #1, there's a bug in the equals method of > EntityDateFilterCondition where all instances appear equal so the cached > result is never replaced until it is expired from the cache. So expired > records remain and future dated records never appear until the TTL is > reached. > > The correct approach is to not have a date filter in the query, cache the > result and then filter the result in-memory using > EntityUtil.filterByDate(). An alternative approach is to only filter by > thruDate in the query since expired records will never become active, and > then filter by fromDate after you have the result. We have no utility > tools in place for the latter approach though. > > I'm writing all this because I've written a checker for the entity list and > object caches that inspect the query conditions for fromDate conditions and > if found, log a warning and refuse to cache. I'd like to add this safety > feature to the OFBiz trunk but I'm wondering if anyone can think of a valid > reason to cache fromDate filtered records? I haven't been able to think of > any but that doesn't necessarily mean there aren't any use cases. > > Thanks > Scott >