private void checkCache()

in src/main/java/org/apache/sling/tracer/internal/TracerLogServlet.java [141:162]


        private void checkCache() {
            final Set<String> toRemove = new HashSet<>();
            final ArrayList<Entry> list = new ArrayList<>(this.cache.values());
            Collections.sort(list);
            if ( this.currentSize > this.maxSize ) {
                while (this.currentSize > this.maxSize && !list.isEmpty()) {
                    final Entry entry = list.remove(0);
                    toRemove.add(entry.recording.getRequestId());
                    currentSize -= entry.recording.size();
                }
            }
            final long time = System.currentTimeMillis() - this.cacheDurationInMillis;
            for(final Entry entry : list) {
                if ( entry.lastAccessed < time ) {
                    toRemove.add(entry.recording.getRequestId());
                    currentSize -= entry.recording.size();
                }
            }
            for(final String key : toRemove) {
                this.cache.remove(key);
            }
        }