Class WeakCache<K,V>
java.lang.Object
dev.engine.core.resource.WeakCache<K,V>
- Type Parameters:
K- the key type (e.g., MeshData, TextureData)V- the value type (e.g., MeshHandle, Handle<TextureResource>)
Identity-based cache with weak reference keys and automatic cleanup.
Maps CPU-side data objects to GPU-side resources using identity semantics.
When the CPU-side data is garbage collected, the associated GPU resource
is queued for cleanup on the next pollStale(Consumer) call.
Lookups are O(1) via identity-hashed weak references.
Thread safety: intended for single-thread access (the render thread).
The GC may enqueue references from any thread, but pollStale(Consumer) is
called from the render thread only.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidDrains all entries, calling cleanup on each value.getOrCreate(K key, Function<K, V> factory) Gets or creates a cached value for the given key.voidPolls for stale entries (keys that were garbage collected).intsize()Returns the number of live entries in the cache.values()Returns all live values in the cache.
-
Constructor Details
-
WeakCache
public WeakCache()
-
-
Method Details
-
getOrCreate
-
pollStale
-
size
public int size()Returns the number of live entries in the cache. -
values
-
clear
-