@Override
    public void run() {
      final long cleanupTimeNs = CLEANUP_TIME_MS * 1000000L;
      long sleepTimeMs = CLEANUP_TIME_MS;
      try {
        while (true) {
          Thread.sleep(sleepTimeMs);
          long timeNs = System.nanoTime();
          long nextCleanupInNs = cleanupTimeNs;
          Iterator<TagState> iter = tagInfo.values().iterator();
          while (iter.hasNext()) {
            TagState v = iter.next();
            synchronized (v) {
              if (v.bufferCount > 0) continue; // The file is still cached.
              long deltaNs = timeNs - v.emptyTimeNs;
              if (deltaNs < cleanupTimeNs) {
                nextCleanupInNs = Math.min(nextCleanupInNs, deltaNs);
                continue;
              } else {
                iter.remove();
              }
            }
          }
          sleepTimeMs = Math.max(MIN_TIME_MS, nextCleanupInNs / 1000000L);
        }
      } catch (InterruptedException ex) {
        return; // Interrupted.
      }
    }
A wrapper around cache eviction policy that tracks cache contents via tags.
llap-server/src/java/org/apache/hadoop/hive/llap/cache/CacheContentsTracker.java