private CompletableFuture<Void> flush(final long indexShardId,
                                          final Executor executor) {
        return securityContext.asProcessingUserResult(() -> {
            final Runnable runnable = taskContextFactory.context(
                    "Flushing writer",
                    TerminateHandlerFactory.NOOP_FACTORY,
                    taskContext -> cache.getIfPresent(indexShardId).ifPresent(indexShardWriter -> {
                        try {
                            taskContext.info(() ->
                                    "Flushing writer for index shard " + indexShardWriter);

                            // Flush the shard.
                            indexShardWriter.flush();
                        } catch (final RuntimeException e) {
                            LOGGER.error(e::getMessage, e);
                        }
                    }));
            return CompletableFuture
                    .runAsync(runnable, executor);
        });
    }
This is called by the lifecycle service and remove writers that are past their TTL, TTI or LRU
items that exceed the capacity.
stroom-index/stroom-index-impl/src/main/java/stroom/index/impl/IndexShardWriterCacheImpl.java