twcache

package
v1.19.21 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidName = errors.New("twcache: cache name escapes the cache directory")

Functions

func DiskCapacityBytes

func DiskCapacityBytes(dir string) (int64, error)

Types

type Cache

type Cache[V any] struct {
	NotFound func(error) bool

	Validate func(V) bool
	// contains filtered or unexported fields
}

func NewDisk added in v1.8.1

func NewDisk(dir string, maxBytes int64, warn func(error)) (*Cache[[]byte], error)

func NewDiskAny added in v1.8.8

func NewDiskAny(dir string, maxBytes int64, warn func(error)) (*Cache[any], error)

func NewMem added in v1.8.1

func NewMem(maxEntries int, maxBytes int64) *Cache[[]byte]

func NewMemFunc added in v1.8.8

func NewMemFunc[V any](maxEntries int, maxBytes int64, weigh func(V) int64) *Cache[V]

func (*Cache[V]) Dir

func (c *Cache[V]) Dir() string

func (*Cache[V]) Get added in v1.8.1

func (c *Cache[V]) Get(ctx context.Context, key string, load LoadFunc[V]) (V, func(), error)

func (*Cache[V]) Invalidate added in v1.8.1

func (c *Cache[V]) Invalidate(key string)

func (*Cache[V]) IsNegative added in v1.8.1

func (c *Cache[V]) IsNegative(key string) bool

func (*Cache[V]) SetLimits added in v1.8.1

func (c *Cache[V]) SetLimits(maxEntries int, maxBytes int64)

func (*Cache[V]) SetWarn added in v1.8.1

func (c *Cache[V]) SetWarn(warn func(error))

func (*Cache[V]) Stats

func (c *Cache[V]) Stats() Stats

type LoadFunc added in v1.8.1

type LoadFunc[V any] func(ctx context.Context) (V, error)

type Stats

type Stats struct {
	Mode            string
	Entries         int
	Bytes           int64
	MaxBytes        int64
	MaxEntries      int
	Hits            uint64
	Misses          uint64
	Evictions       uint64
	Failures        uint64
	NotFound        uint64
	NegativeHits    uint64
	NegativeEntries int
	LastParseMs     float64
}

Jump to

Keyboard shortcuts

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