Add cache invalidation strategy to AbstractQuery

By adding the cached timestamps of the involved entity tables to the query hash, we will invalidate the cache when any of those tables have changed.