cache

package
v0.0.0-...-27647ab Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2023 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMaxSize = 256

Variables

This section is empty.

Functions

func PanicOnOverweight

func PanicOnOverweight(k, v any)

Types

type Cache

type Cache[K comparable] struct {
	// contains filtered or unexported fields
}

func NewCache

func NewCache[K comparable](cfg Config) *Cache[K]

func (*Cache[K]) Clear

func (c *Cache[K]) Clear()

func (*Cache[K]) Contains

func (c *Cache[K]) Contains(k K) bool

func (*Cache[K]) Delete

func (c *Cache[K]) Delete(k K) bool

func (*Cache[K]) ForEach

func (c *Cache[K]) ForEach(fn func(bt.Kv[K, any]) bool) bool

func (*Cache[K]) Get

func (c *Cache[K]) Get(k K) any

func (*Cache[K]) Iterate

func (c *Cache[K]) Iterate() bt.Iterator[bt.Kv[K, any]]

func (*Cache[K]) Len

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

func (*Cache[K]) Put

func (c *Cache[K]) Put(k K, v any) bool

func (*Cache[K]) Reap

func (c *Cache[K]) Reap()

func (*Cache[K]) TryGet

func (c *Cache[K]) TryGet(k K) (any, bool)

type Config

type Config struct {
	MaxSize int

	Weigher   func(v any) Weight
	MaxWeight Weight

	ExpireAfterAccess time.Duration
	ExpireAfterWrite  time.Duration

	OnAdd        func(k, v any)
	OnRemove     func(k, v any)
	OnOverweight func(k, v any)

	Clock func() time.Time

	Lock sync.Locker

	Eviction Eviction

	TrackFrequency bool
}

func DefaultConfig

func DefaultConfig() Config

type Eviction

type Eviction interface {
	// contains filtered or unexported methods
}

type LFU

type LFU struct{}

type LRI

type LRI struct{}

type LRU

type LRU struct{}

type OverweightError

type OverweightError struct {
	Key, Value any
}

func (OverweightError) Error

func (e OverweightError) Error() string

type Stats

type Stats struct {
	Seq int

	Size   int
	Weight Weight

	Hits   int
	Misses int

	MaxSizeEver   int
	MaxWeightEver Weight
}

type Weight

type Weight = float32

Jump to

Keyboard shortcuts

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