parsecache

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package parsecache memoizes parser results so repeated registrations of the same spec share one parsed value and pay the parse cost once.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache[T any] struct {
	// Limit softly caps stored entries; <= 0 means unbounded. When full, Get
	// builds without memoizing.
	Limit int64
	// contains filtered or unexported fields
}

Cache is a typed memoizing store. The zero value is ready and unbounded. It is safe for concurrent use.

func (*Cache[T]) Forget

func (c *Cache[T]) Forget(spec string)

Forget drops spec's memoized result, if any, freeing its Limit slot.

func (*Cache[T]) Get

func (c *Cache[T]) Get(spec string, build func() (T, error)) (T, error)

Get returns the memoized result for spec, building it with build on first use; concurrent callers for the same spec share one build. Errors are memoized too, so a caller that does not want to pin a failure must Forget it. Once Limit is reached the value is built without being stored.

func (*Cache[T]) Len

func (c *Cache[T]) Len() int

Len reports the number of stored entries. It walks the map, so it is meant for tests and diagnostics rather than hot paths.

type ParseFunc

type ParseFunc[T any] func() (T, error)

ParseFunc produces a value. The cache stores builders wrapped in sync.OnceValues, so concurrent first callers share a single build.

Jump to

Keyboard shortcuts

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