Added synchronization blocks to functions retrieving objects from CacheHashMaps and made the API use one for caching item stacks as well.

This commit is contained in:
Luis C.M committed 2023-05-31 00:35:57 -05:00
1 parent 3bc02a708e
commit 118d79f3ad
4 files changed
+34 -53

No files matched your search

@@ -4,13 +4,14 @@ import noppes.npcs.client.renderer.customitem.ImageData;
import noppes.npcs.util.CacheHashMap;
public class ClientCache {
private static final CacheHashMap<String, CacheHashMap.CachedObject<ImageData>> imageDataCache = new CacheHashMap<>(10*1000);
private static final CacheHashMap<String, CacheHashMap.CachedObject<ImageData>> imageDataCache = new CacheHashMap<>(10*60*1000);
public static ImageData getImageData(String directory) {
if (!imageDataCache.containsKey(directory)) {
ImageData imageData = new ImageData(directory);
imageDataCache.put(directory, new CacheHashMap.CachedObject<>(imageData));
synchronized (imageDataCache) {
if (!imageDataCache.containsKey(directory)) {
imageDataCache.put(directory, new CacheHashMap.CachedObject<>(new ImageData(directory)));
}
return imageDataCache.get(directory).getObject();
}
return imageDataCache.get(directory).getObject();
}
}