cache

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

func (*Cache) ComputeIfAbsent

func (c *Cache) ComputeIfAbsent(key string, f func()) bool

func (*Cache) Get

func (c *Cache) Get(key string) (any, bool)

Get 获取缓存值(如果不存在,返回 nil 和 false)

func (*Cache) Init

func (c *Cache) Init(context context.Context, config config2.IConfig) error

func (*Cache) Invalidate

func (c *Cache) Invalidate(key string) (any, bool)

func (*Cache) Set

func (c *Cache) Set(key string, value any)

Set 设置缓存值(无过期时间,除非全局配置了 ExpiryCalculator)

func (*Cache) SetIfAbsent

func (c *Cache) SetIfAbsent(key string, value any) (any, bool)

func (*Cache) SetNX

func (c *Cache) SetNX(key string, value any, expire time.Duration) (any, bool)

SetNX 设置缓存值(有过期时间), 如果已存在则返回 false, 否则返回 true

func (*Cache) Stats

func (c *Cache) Stats() stats.Stats

type Config

type Config struct {
	MaxSize int // 最大缓存数量
	Expiry  int // 缓存过期时间 单位秒
}

Jump to

Keyboard shortcuts

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