@Override
    public void deleteEntriesUsingCachePolicy(int numRowsToDelete) {
        IndexEventHolder indexEventHolder = (IndexEventHolder) stateHolder.getState().getEventHolder();
        if (numRowsToDelete >= indexEventHolder.size()) {
            indexEventHolder.deleteAll();
        } else {
            Set<Object> keys = indexEventHolder.getAllPrimaryKeyValues();
            TreeMap<Long, Object> toDelete = new TreeMap<>();
            for (Object key : keys) {
                if (toDelete.size() < numRowsToDelete) {
                    toDelete.put((Long) indexEventHolder.getEvent(key).getOutputData()[cachePolicyAttributePosition],
                            key);
                } else {
                    Long timestamp = (Long) indexEventHolder.getEvent(key).
                            getOutputData()[cachePolicyAttributePosition];
                    Long firstKey = toDelete.firstKey();
                    if (timestamp < firstKey) {
                        toDelete.remove(firstKey);
                        toDelete.put(timestamp, key);
                    }
                }
            }
            for (Object deleteKey : toDelete.values()) {
                if (deleteKey != null) {
                    indexEventHolder.deleteEvent(deleteKey);
                }
            }
        }
    }
cache table with FIFO entry removal
modules/siddhi-core/src/main/java/io/siddhi/core/table/CacheTableFIFO.java