public void handleCache(int rowIdx, PTFPartition p) throws HiveException {
    BoundaryCache cache = p.getBoundaryCache();
    if (cache == null) {
      return;
    }

    //No need to setup/fill cache.
    if (start.isUnbounded() && end.isUnbounded()) {
      return;
    }

    //Start of partition.
    if (rowIdx == 0) {
      cache.clear();
    }
    if (cache.isComplete()) {
      return;
    }
    if (cache.isEmpty()) {
      fillCacheUntilEndOrFull(rowIdx, p);
      return;
    }

    if (start.isPreceding()) {
      if (start.isUnbounded()) {
        if (end.isPreceding()) {
          //We can wait with cache eviction until we're at the end of currently known ranges.
          Map.Entry<Integer, Object> maxEntry = cache.getMaxEntry();
          if (maxEntry != null && maxEntry.getKey() <= rowIdx) {
            cache.evictOne();
          }
        } else {
          //Starting from current row, all previous ranges can be evicted.
          checkIfCacheCanEvict(rowIdx, p, true);
        }
      } else {
        //We either evict when we're at the end of currently known ranges, or if not there yet and
        // END is of FOLLOWING type: we should remove ranges preceding the current range beginning.
        Map.Entry<Integer, Object> maxEntry = cache.getMaxEntry();
        if (maxEntry != null && maxEntry.getKey() <= rowIdx) {
          cache.evictOne();
        } else if (end.isFollowing()) {
          int startIdx = computeStart(rowIdx, p);
          checkIfCacheCanEvict(startIdx - 1, p, true);
        }
      }
    }

    if (start.isCurrentRow()) {
      //Starting from current row, all previous ranges before the previous range can be evicted.
      checkIfCacheCanEvict(rowIdx, p, false);
    }
    if (start.isFollowing()) {
      //Starting from current row, all previous ranges can be evicted.
      checkIfCacheCanEvict(rowIdx, p, true);
    }

    fillCacheUntilEndOrFull(rowIdx, p);
  }
Checks and maintains cache content - optimizes cache window to always be around current row
thereby makes it follow the current progress.
@param rowIdx current row
@param p current partition for the PTF operator
@throws HiveException
ql/src/java/org/apache/hadoop/hive/ql/udf/ptf/ValueBoundaryScanner.java