HotEntryCache will update Instants only once per second

Calling Instant.now() several hundred thousand times per
second can be expensive. In my measurements >10% of the
time spend when loading new data was spend calling
Instant.now().
Fixed this by storing an Instant as static member and
updating it periodically in a separate thread.
This commit is contained in:
2018-12-21 19:16:55 +01:00
parent d95a71e32e
commit e537e94d39
4 changed files with 107 additions and 30 deletions

View File

@@ -71,7 +71,7 @@ public class TagsToFile implements AutoCloseable {
public TagsToFile(final DataStore dataStore) {
this.dataStore = dataStore;
writerCache = new HotEntryCache<>(Duration.ofSeconds(10));
writerCache = new HotEntryCache<>(Duration.ofSeconds(10), "writerCache");
writerCache.addListener(new RemovalListener(), EventType.EVICTED, EventType.REMOVED);
}