@mocanvas/editor · function

createCachedUserResolve

declare function createCachedUserResolve(resolve: UserStore["resolve"], options?: CreateCachedUserResolveOptions): CachedUserResolve

Wrap a UserStore's resolve so the same id is not looked up twice.

The render path asks for a name once per attributed shape, per frame. Without a cache that is one lookup per shape per frame — and if the store is async, one *request*. This collapses them: an in-flight promise is shared rather than duplicated, and a settled answer is reused until it expires.

A null answer is cached too, deliberately. "This id is not a person I know" is a real answer, and re-asking for it on every frame is exactly the case a cache exists to prevent — a board full of shapes attributed to a departed colleague would otherwise never stop asking.

Failures are *not* cached: a lookup that threw gets another chance, because a network blip should not blank out a name for the rest of the session.

Mentioned here

mocanvas is built by Symbio. Free for non-commercial, non-profit and development use; commercial use needs an agreement. Not affiliated with or endorsed by tldraw.