CacheHashMap:

-New class extending from the HashMap class, only takes CacheHashMap.CachedObject as values, which itself is a template class.
-On every call to get(), it goes through its values and removes any that are past a set age in millis.

ClientCache:
-New class with static CacheHashMap and function to get image data, will do more caching later on.
This commit is contained in:
Luis C.M committed 2023-05-30 23:41:37 -05:00
1 parent ab8e966f71
commit 46febe5c0a
6 files changed
+83 -17

No files matched your search

@@ -0,0 +1,16 @@
package noppes.npcs.client;
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);
public static ImageData getImageData(String directory) {
if (!imageDataCache.containsKey(directory)) {
ImageData imageData = new ImageData(directory);
imageDataCache.put(directory, new CacheHashMap.CachedObject<>(imageData));
}
return imageDataCache.get(directory).getObject();
}
}