Documentation ¶
Overview ¶
Package gocache 用于并发场景,支持自动化LRU,支持singlefight更新缓存
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrKeyNotFound key不存在错误 ErrKeyNotFound = fmt.Errorf("key not found") // ErrKeyIsExpired key过期错误 ErrKeyIsExpired = fmt.Errorf("key is expired") )
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache 缓存核心结构
type CacheOpt ¶
type CacheOpt struct {
// contains filtered or unexported fields
}
CacheOpt Cache参数选项结构
type GoCacheBuilder ¶ added in v1.1.4
type GoCacheBuilder struct {
// contains filtered or unexported fields
}
GoCacheBuilder 缓存功能基础结构定义
func NewGoCacheBuilder ¶ added in v1.1.4
func NewGoCacheBuilder(opts ...GoCacheBuilderOptHelper) *GoCacheBuilder
NewGoCacheBuilder GoCacheBuilder的构造函数
func (*GoCacheBuilder) Get ¶ added in v1.1.4
func (c *GoCacheBuilder) Get(ctx context.Context, key string, fn UpdateHelper) (interface{}, error)
Get 获取val,若val存在且未过期,则更新至缓存,否则通过singleflight的方式更新至缓存 若更新失败,则使用旧数据兜底并返回对应的error给调用方
type GoCacheBuilderOpt ¶ added in v1.1.4
type GoCacheBuilderOpt struct {
// contains filtered or unexported fields
}
GoCacheBuilderOpt cache相关配置
type GoCacheBuilderOptHelper ¶ added in v1.1.4
type GoCacheBuilderOptHelper func(opts *GoCacheBuilderOpt)
GoCacheBuilderOptHelper GoCacheBuilderOpt结构helper
func WithExpire ¶
func WithExpire(expire time.Duration) GoCacheBuilderOptHelper
WithExpire 设置key过期时间
type UpdateCallback ¶ added in v0.0.2
type UpdateCallback func() (interface{}, error)
UpdateCallback 更新数据回调
type UpdateHelper ¶ added in v1.1.4
type UpdateHelper func() (val interface{}, err error)
UpdateHelper 更新功能helper
Click to show internal directories.
Click to hide internal directories.