Documentation
¶
Overview ¶
Package cache holds the caches the gfx backends keep per Renderer, bounded so that a scene which keeps making new strings, shadows or Rasters does not grow them without end. All are safe for concurrent use; a value is never released while a draw on another goroutine may still use it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Gen ¶
type Gen[K comparable, V any] struct { Max int // contains filtered or unexported fields }
Gen keeps two generations of at most Max entries; a hit in the old one moves the entry to the current one, so what every frame draws survives while a frame adds fewer than Max new keys. A dropped value is only unreferenced: a native one is released by its runtime.AddCleanup.
func (*Gen[K, V]) LoadOrStore ¶
LoadOrStore returns the value cached for k if there is one, else caches v; loaded is true when v was not stored and the caller still owns it.
type Weak ¶
type Weak[K, V any] struct { // contains filtered or unexported fields }
Weak maps a *K to a value without keeping the K alive; once the K is collected, release runs on the value on the cleanup goroutine, so a draw that uses the value keeps the K alive until done.
func (*Weak[K, V]) Drain ¶
func (c *Weak[K, V]) Drain(release func(V))
Drain removes every entry and releases its value now; the cleanups of the keys find nothing left.
func (*Weak[K, V]) LoadOrStore ¶
LoadOrStore returns the value stored for p if there is one, else stores v, to be released with release once p is unreachable; loaded is true when v was not stored and the caller still owns it.