cache

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ICache

type ICache[T any] interface {
	// Get 获取缓存,返回缓存数据的 json 字符串,ttl, 和错误
	Get(ctx context.Context, key string) (*T, time.Duration, error)
	// Pull 获取缓存,并删除缓存
	Pull(ctx context.Context, key string) (*T, error)
	// Set 设置缓存
	Set(ctx context.Context, key string, val *T, expire time.Duration) error
	// Remember 如果缓存不存在,则通过 fun 函数获取数据,并缓存。该函数返回 缓存数据和错误
	Remember(ctx context.Context, key string, expire time.Duration, fun func(ctx context.Context) (*T, error)) (*T, error)
	// Clear 清理缓存
	Clear(ctx context.Context, key string) error
}

func New

func New[T any](nameSpace string, cacheManager *cache.Cache[T]) ICache[T]

Jump to

Keyboard shortcuts

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