Skip to content

Commit

Permalink
Fixed image memory cache invalidation
Browse files Browse the repository at this point in the history
- Updated ImageFile#getMapsAndSubscribe()
- Invalidated image file on image removal
  • Loading branch information
josemmo committed Jun 18, 2021
1 parent c5a6ce3 commit 1184e5f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Expand Up @@ -250,6 +250,7 @@ public void removeImage(@NotNull FakeImage image) {
worldAreas.remove(worldAreaId);
}
}
image.invalidate();

// Set configuration changed flag
hasConfigChanged.set(true);
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/io/josemmo/bukkit/plugin/storage/ImageFile.java
Expand Up @@ -113,6 +113,10 @@ public long getLastModified() {
int height = subscriber.getHeight();
String cacheKey = width + "-" + height;

// Update subscribers for given cached maps
subscribers.computeIfAbsent(cacheKey, __ -> new HashSet<>());
subscribers.get(cacheKey).add(subscriber);

// Try to get maps from memory cache
if (cache.containsKey(cacheKey)) {
return cache.get(cacheKey);
Expand Down Expand Up @@ -167,10 +171,6 @@ public long getLastModified() {
plugin.log(Level.SEVERE, "Failed to get image data from file \"" + path + "\"", e);
}

// Update subscribers for given cached maps
subscribers.computeIfAbsent(cacheKey, __ -> new HashSet<>());
subscribers.get(cacheKey).add(subscriber);

// Persist in memory cache and return
cache.put(cacheKey, matrix);
return matrix;
Expand Down

0 comments on commit 1184e5f

Please sign in to comment.