qcache

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Caches

type Caches[T any] struct {
	// contains filtered or unexported fields
}

func NewCaches

func NewCaches[T any](defaultExpiration, cleanupInterval time.Duration, findingCallback func(key string) (T, bool)) *Caches[T]

NewCaches 创建缓存

@param defaultExpiration 缓存项的默认过期时间
@param cleanupInterval 清理过期缓存项的时间间隔 0不清理 非0间隔清理
@param findingCallback Get缓存不存在时,主动查找回调方法
@return *Caches[T]

func (*Caches[T]) Delete

func (c *Caches[T]) Delete(key string)

Delete 删除缓存

@param key

func (*Caches[T]) Get

func (c *Caches[T]) Get(key string) (T, bool)

Get 获取缓存

@param key
@return T

func (*Caches[T]) LoadFromFile

func (c *Caches[T]) LoadFromFile(filePath string) error

LoadFromFile 从文件加载缓存

@param filePath 文件路径
@return error

func (*Caches[T]) SaveToFile

func (c *Caches[T]) SaveToFile(filePath string) error

SaveToFile 将缓存保存到文件

@param filePath 文件路径
@return error

func (*Caches[T]) Set

func (c *Caches[T]) Set(key string, value T)

Set 写入缓存,使用默认的缓存有效期

@param key
@param value
@param newExpiration

func (*Caches[T]) SetWithNewExpiration

func (c *Caches[T]) SetWithNewExpiration(key string, value T, newExpiration time.Duration)

SetWithNewExpiration 写入缓存, 使用新的缓存有效期

@param key
@param value
@param newExpiration

Jump to

Keyboard shortcuts

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