lazyloadx

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNilFunction = errors.New("lazyloadx: New function is nil")

Functions

This section is empty.

Types

type Group

type Group[Obj any] struct {

	// New 一个函数指针,用于创建新的值。
	New func(key string) (Obj, error)
	// contains filtered or unexported fields
}

Group 用于实现缓存和懒加载功能

func (*Group[Obj]) Delete

func (g *Group[Obj]) Delete(key string)

Delete 删除指定的键值对。

func (*Group[Obj]) Load

func (g *Group[Obj]) Load(key string) (Obj, error, bool)

Load 用于获取键对应的值。如果 key 不存在,则调用 g.New 创建新值。

func (*Group[Obj]) LoadOrNew

func (g *Group[Obj]) LoadOrNew(key string, f func(key string) (Obj, error)) (Obj, error, bool)

LoadOrNew 用于获取键对应的值。如果 key 不存在,则调用 f 或 g.New 创建新值。

func (*Group[Obj]) Range

func (g *Group[Obj]) Range(f func(key string, value Obj) bool)

Range 遍历所有键值对,并调用 f 函数。

Jump to

Keyboard shortcuts

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