createQuery only if necessary
manage query caching only when relevant