cache

package
v0.15.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2026 License: EPL-2.0 Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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]) Clear

func (c *Gen[K, V]) Clear()

Clear drops every entry.

func (*Gen[K, V]) Len

func (c *Gen[K, V]) Len() int

Len counts the entries of both generations; one in both counts twice.

func (*Gen[K, V]) Load

func (c *Gen[K, V]) Load(k K) (V, bool)

Load returns the value cached for k.

func (*Gen[K, V]) LoadOrStore

func (c *Gen[K, V]) LoadOrStore(k K, v V) (actual V, loaded bool)

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.

func (*Gen[K, V]) Misses

func (c *Gen[K, V]) Misses() int64

Misses is the number of LoadOrStore calls: the values that had to be made.

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]) Len

func (c *Weak[K, V]) Len() int

Len is the number of entries.

func (*Weak[K, V]) Load

func (c *Weak[K, V]) Load(p *K) (V, bool)

Load returns the value stored for p.

func (*Weak[K, V]) LoadOrStore

func (c *Weak[K, V]) LoadOrStore(p *K, v V, release func(V)) (actual V, loaded bool)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL