cache

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnyCache

type AnyCache[T comparable] struct {
	// contains filtered or unexported fields
}

Cache 一个可并发、防击穿的LRU算法 最小长度缓存为1,达到缓存上限时,淘汰最久未访问的数据 直接使用时,自动使用最小缓存长度

func NewAnyCache

func NewAnyCache[T comparable](maxCacheLen uint16, outTime time.Duration) *AnyCache[T]

NewCache 根据输入缓存长度生成AnyCache对象

func (*AnyCache[T]) Clear

func (c *AnyCache[T]) Clear()

func (*AnyCache[T]) Delete

func (c *AnyCache[T]) Delete(k T)

Delete 根据key主动删除缓存

func (*AnyCache[T]) Load

func (c *AnyCache[T]) Load(k T) (any, bool)

func (*AnyCache[T]) LoadOrStore

func (c *AnyCache[T]) LoadOrStore(k T, fu func() (any, error)) (any, error)

LoadOrStore 根据key读取数据,当没有数据时,根据输入的方法存储并返回数据

func (*AnyCache[T]) Store

func (c *AnyCache[T]) Store(key T, data any)

Store 存储key-value数据

type Cache

type Cache[T1, T2 comparable] struct {
	// contains filtered or unexported fields
}

Cache 一个可并发、防击穿的LRU算法 最小长度缓存为1,达到缓存上限时,淘汰最久未访问的数据 直接使用时,自动使用最小缓存长度

func NewCache

func NewCache[T1, T2 comparable](maxCacheLen uint16, outTime time.Duration) *Cache[T1, T2]

NewCache 根据输入缓存长度生成Cache对象

func (*Cache[T1, T2]) Clear

func (c *Cache[T1, T2]) Clear()

func (*Cache[T1, T2]) Delete

func (c *Cache[T1, T2]) Delete(k T1)

Delete 根据key主动删除缓存

func (*Cache[T1, T2]) Load

func (c *Cache[T1, T2]) Load(k T1) (T2, bool)

func (*Cache[T1, T2]) LoadOrStore

func (c *Cache[T1, T2]) LoadOrStore(k T1, fu func() (T2, error)) (T2, error)

LoadOrStore 根据key读取数据,当没有数据时,根据输入的方法存储并返回数据

func (*Cache[T1, T2]) Store

func (c *Cache[T1, T2]) Store(key T1, data T2)

Store 存储key-value数据

type CancelMgr

type CancelMgr[T comparable] struct {
	// contains filtered or unexported fields
}

用于超时任务操作集

func NewCancelMgr

func NewCancelMgr[T comparable]() *CancelMgr[T]

func (*CancelMgr[T]) Cancel

func (i *CancelMgr[T]) Cancel(key T)

func (*CancelMgr[T]) Store

func (i *CancelMgr[T]) Store(key T, value context.CancelFunc)

type MulSet

type MulSet[T comparable] struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

可重复插入的Set,一般用于作为任务锁

func NewMulSet

func NewMulSet[T comparable]() *MulSet[T]

func (*MulSet[T]) Add

func (s *MulSet[T]) Add(k T)

func (*MulSet[T]) Contains

func (s *MulSet[T]) Contains(k T) bool

func (*MulSet[T]) Remove

func (s *MulSet[T]) Remove(k T)

Jump to

Keyboard shortcuts

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