group

package
v0.0.0-...-b628505 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Group

type Group struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Group 懒加载容器

func (*Group) Clear

func (g *Group) Clear()
Example
// 清空缓存的 buffer
group.Clear()
Output:

func (*Group) Get

func (g *Group) Get(key string) interface{}

Get 根据key 获取 value

Example
// 如果key 不存在 调用 NewGroup 传入的 function 创建资源
// 如果存在则返回创建的资源信息
v := group.Get("test")
_ = v
Output:

func (*Group) ReSet

func (g *Group) ReSet(nf func() interface{})

ReSet 更换实例化函数

Example
// ReSet 重置初始化函数,同时会对缓存的 key进行清空
group.ReSet(createResources2)
Output:

type LazyLoadGroup

type LazyLoadGroup interface {
	Get(key string) interface{}
	ReSet(nf func() interface{})
	Clear()
}

LazyLoadGroup 懒加载结构化

func NewGroup

func NewGroup(f func() interface{}) LazyLoadGroup

NewGroup Group 实例化方法

Example
// 类似 sync.Pool 一样
// 初始化一个group
group = NewGroup(createResources)
Output:

Jump to

Keyboard shortcuts

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