AssetCache Class
Internal singleton that owns the asset caches, ref counts and native resource lifecycle. All public API goes through AssetLoader (the scoped IAssetLoader wrapper).
internal sealed class AssetCache : System.IAsyncDisposable
Inheritance System.Object → AssetCache
Implements System.IAsyncDisposable
| Methods | |
|---|---|
| CancelPreloadsAndClearState() | Cancels active preloads, snapshots tracked manifests, and clears all ref-count bookkeeping. Must be called under Brine2D.Assets.AssetCache._stateLock. Returns the manifests whose IAssetRefs need to be reset outside the lock. |
| ExecuteLoadAsync<TKey,T>(TKey, TypedCache<TKey,T>, Func<CancellationToken,Task<T>>, long, TaskCompletionSource<T>) | Runs the I/O load on the thread pool and writes the result to the cache under the lock. If the inflight entry was removed (by Brine2D.Assets.AssetCache.Unload(Brine2D.Assets.AssetManifest) or Brine2D.Assets.AssetCache.UnloadAll) while the load was in progress, the native resource is freed immediately outside the lock and the System.Threading.Tasks.TaskCompletionSource<> is cancelled. |
| GetOrLoadAsync<TKey,T>(TKey, TypedCache<TKey,T>, Func<CancellationToken,Task<T>>, CancellationToken) | Returns a cached asset, joins an in-flight load, or starts a new one. The lock is held only for dictionary lookups/writes — never across I/O. |