sql - Hibernate query cache based on current time -
i have dao method executes following query fetch results:
select new com.person() person person (person.start <= now()) , (person.expires > now()) order person.start asc
the above postgresql query. can enable query caching on above? if query.setquerycache(true)
, wouldn't work because now() different each time above executed. there best practice implement such functionality?
basically should use discrete values instead of using directly value of now(), new 1 , incompatible caching strategy i've heard of :).
so you're looking cache data each 15 minutes. you'd have floor value of now() closest quarter of hour , use floored value in sql query instead.
you can check out article on stack implementing such thing how round time nearest quarter hour in java?
Comments
Post a Comment