cache

package
v1.5.5 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExpiringCache added in v1.5.0

type ExpiringCache struct {
	// contains filtered or unexported fields
}

缓存结构体

func DefaultCache added in v1.5.0

func DefaultCache() *ExpiringCache

func NewExpiringCache added in v1.5.0

func NewExpiringCache(opts ...Option) *ExpiringCache

新建缓存实例

func (*ExpiringCache) Clear added in v1.5.0

func (c *ExpiringCache) Clear()

清除所有缓存项

func (*ExpiringCache) Close added in v1.5.0

func (c *ExpiringCache) Close()

关闭缓存,停止清理goroutine

func (*ExpiringCache) Delete added in v1.5.0

func (c *ExpiringCache) Delete(key string)

删除缓存项

func (*ExpiringCache) Get added in v1.5.0

func (c *ExpiringCache) Get(key string) (interface{}, bool)

获取缓存项

func (*ExpiringCache) Set added in v1.5.0

func (c *ExpiringCache) Set(key string, value interface{})

设置缓存项,使用默认过期时间

func (*ExpiringCache) SetWithTTL added in v1.5.0

func (c *ExpiringCache) SetWithTTL(key string, value interface{}, ttl time.Duration)

设置缓存项,指定过期时间

func (*ExpiringCache) Size added in v1.5.0

func (c *ExpiringCache) Size() int

获取当前缓存大小

type Option added in v1.5.0

type Option func(*ExpiringCache)

选项函数,用于配置缓存

func WithCleanupInterval added in v1.5.0

func WithCleanupInterval(interval time.Duration) Option

WithCleanupInterval 设置清理间隔

func WithEvictionCallback added in v1.5.0

func WithEvictionCallback(callback func(key string, value interface{})) Option

WithEvictionCallback 设置淘汰回调函数

func WithMaxSize added in v1.5.0

func WithMaxSize(maxSize int) Option

WithMaxSize 设置最大缓存大小,用于LRU淘汰

func WithTTL added in v1.5.0

func WithTTL(ttl time.Duration) Option

WithTTL 设置默认过期时间

Jump to

Keyboard shortcuts

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