cache

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// DefaultMaxBufFactor 默认扩展因子, 用来计算全局扩展缓存
	DefaultMaxBufFactor = 0.2

	// DefaultMinBufSize 默认最小缓存
	DefaultMinBufSize = 1024 * 1024

	// DefaultMaxBufSize 默认最大缓存512M
	DefaultMaxBufSize = 512 * 1024 * 1024
)
View Source
const Name = "cache"

Variables

View Source
var (
	Err                = xerror.New(Name)
	ErrNotFound        = Err.New("key不存在")
	ErrKeyExpired      = Err.New("缓存过期")
	ErrKeyLength       = Err.New("key长度范围设置错误")
	ErrBufExceeded     = Err.New("现有的缓存超过了最大的缓存限制")
	ErrExpiration      = Err.New("过期时间设置错误")
	ErrDataLoadTimeOut = Err.New("DataLoad执行超时")
	ErrClearTime       = Err.New("定时清理过期缓存时间设置错误")
)

Functions

func Delete

func Delete(k string) error

Delete 全局删除缓存

func Get

func Get(k string) (interface{}, error)

Get 全局获取缓存

func GetSet

func GetSet(k string, d time.Duration, fn ...getCallback) (interface{}, error)

GetSet 自定义过期时间获取或者设置缓存

func Register added in v0.1.0

func Register(name string, store Factory)

func Set

func Set(k string, x interface{}, ds time.Duration) error

Set 全局存储缓存

func SetDefault added in v0.1.2

func SetDefault(c *cacheImpl)

Types

type Cfg added in v0.1.2

type Cfg struct {
	Store             string
	DataLoadTime      time.Duration
	ClearTime         time.Duration
	MaxBufSize        uint32
	DefaultExpiration time.Duration
	MaxExpiration     time.Duration
	MaxKeySize        uint32
}

Cfg 缓存配置变量

func GetDefaultCfg added in v0.1.2

func GetDefaultCfg() Cfg

func (Cfg) Build added in v0.1.2

func (t Cfg) Build() (_ *cacheImpl, err error)

type Factory added in v0.1.0

type Factory func(cfg map[string]interface{}) (IStore, error)

type IStore added in v0.1.0

type IStore interface {
	OnEvicted(func(key string, obj []byte))
	Get(key string) (obj []byte, err error)
	GetExpired(key string) (obj []byte, expired time.Time, err error)
	Set(key string, obj []byte, dur ...time.Duration) error
	Delete(key string) error
	DeleteExpired() error
	Close() error
}

func GetStore added in v0.1.2

func GetStore(names ...string) IStore

Directories

Path Synopsis
stores

Jump to

Keyboard shortcuts

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