Skip to content

Commit

Permalink
Add index caching
Browse files Browse the repository at this point in the history
  • Loading branch information
denis256 committed Apr 23, 2023
1 parent dc47e08 commit 0b136cb
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,20 @@ public Optional<BasicPoly> index(String poly) {
if (!exists(poly)) {
return Optional.empty();
}
BasicPoly cachedResult = ifCache(cache -> {
String key = poly + "-index";
return cache.get(key);
});
if (cachedResult != null) {
return Optional.of(cachedResult);
}
BasicPoly index = new BasicPoly();
MongoCollection<Document> collection = indexCollection(poly);
for (Document document : collection.find()) {
BasicPoly value = toPoly(document);
index.put(value._id(), value);
}
putIfCache(poly + "-index", index);
return Optional.of(index);
}

Expand Down

0 comments on commit 0b136cb

Please sign in to comment.