Class SkinAvatarCache<H>

java.lang.Object
lol.trq.alts.skin.SkinAvatarCache<H>
Type Parameters:
H - the host's opaque texture-handle type

public final class SkinAvatarCache<H> extends Object
In-memory cache of player face avatars, keyed by UUID. The bytes come from the runtime's AvatarSource (by default one that crops the face from Mojang's own skin); downloads happen on the runtime's executor, a few at a time, and GPU uploads are marshalled onto the host's main/render thread via MainThreadExecutor and produced by the host's TextureUploader.

Keyed by UUID, not username. A username is a mutable display attribute — a rename leaves a cache keyed on the old one pointing at nothing, so the head breaks for good. The UUID is the stable identity, so the head survives a name change.

The handle type H is the host renderer's opaque texture type, so this cache serves any renderer (NanoVG, Skija, …) unchanged — only the eventual blit differs and stays host-side.

Entry states (a ConcurrentHashMap forbids nulls, so each is a real sentinel):

  • absent from map → not requested yet
  • a SkinAvatarCache.Pending → fetch in flight; one instance per fetch, so a fetch overtaken by invalidate(String) cannot write its stale result back
  • a SkinAvatarCache.Failed → a fetch failed; retried after a growing backoff, not forever abandoned
  • a host handle → ready to draw

There is no public constructor: AltsRuntime#skinCache() returns the runtime's one cache.

Since:
0.1.0
  • Method Details

    • get

      public H get(String uuid)
      Returns the cached avatar for uuid if ready, otherwise null. On a cache miss, or on a past failure whose backoff has elapsed, this starts an async fetch so a later frame can pick it up.
      Parameters:
      uuid - the player UUID to resolve an avatar for; null or blank yields null
      Returns:
      the ready handle, or null while a fetch is pending, is backing off, or was just started
      Since:
      0.1.0, keyed on the player's UUID since 0.10.0
    • invalidate

      public H invalidate(String uuid)
      Drops the cached avatar for uuid, so the next get(String) fetches it again. For a skin the host knows has changed: without this the old head is served for the life of the process.

      A fetch already in flight for this UUID is abandoned; its result is discarded rather than stored, since it may predate the change.

      Parameters:
      uuid - the player UUID whose avatar to drop; null or blank is a no-op
      Returns:
      the handle that was cached, for the host to release, or null if none was ready
      Since:
      0.12.0