/** * Check if this is a new query. If so, clean up the cache * that is for the previous query, and reset the current query id. */ public static void initialize(Configuration conf) { String currentQueryId = conf.get(HiveConf.ConfVars.HIVEQUERYID.varname); if (!currentQueryId.equals(queryId)) { if (TABLE_CONTAINER_CACHE.size() != 0) { synchronized (TABLE_CONTAINER_CACHE) { if (!currentQueryId.equals(queryId) && TABLE_CONTAINER_CACHE.size() != 0) { TABLE_CONTAINER_CACHE.clear((path, tableContainer) -> tableContainer.clear()); LOG.debug("Cleaned up small table cache for query {}", queryId); } } } queryId = currentQueryId; } }
@Test public void testClear() throws ExecutionException { cache.get(KEY, () -> { counter.incrementAndGet(); return new String(TEST_VALUE_1); }); cache.clear((k, v) -> { }); assertEquals(1, counter.get()); assertEquals(0, cache.size()); }