private Query getCachedQuery(Session session, int[] masks) { final CacheKey cacheKey = new CacheKey(masks, session); synchronized (this) { Query q = queryCache.get(cacheKey); if (q == null) { q = getQuery(session, masks); queryCache.put(cacheKey, q); } return q; } }