core

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const NoExpire time.Duration = 0

Variables

View Source
var (
	CacheExist           = errors.New("cache exist")             // 缓存存在
	CacheNoExist         = errors.New("cache no exist")          // 缓存不存在
	CacheExpire          = errors.New("cache expire")            // 缓存过期
	NoCacheDriver        = errors.New("cache No Driver")         // 没有该驱动
	NoCacheFile          = errors.New("cache No File")           // 没有找到存缓存的文件
	OpenCacheFileFail    = errors.New("open cache file fail")    // 打开存的文件失败
	CreateCacheDirFail   = errors.New("create cache dir fail")   // 创建文件夹
	RedisCacheConfigFail = errors.New("redis cache config fail") // redis 配置错误
)

Functions

This section is empty.

Types

type Cache

type Cache struct {
	// 缓存map
	Items map[string]Item
	// 锁
	SM sync.RWMutex
	// 不过期时间
	NoExpire time.Duration
	// 前缀
	Prefix string
}

缓存结构体

type CacheInterface

type CacheInterface interface {

	// 设置值 参数1:key  , 参数2:value , 参数2:有效时间 ; 如果存在则直接覆盖
	Set(string, interface{}, time.Duration) bool

	// 设置值 参数1:key  , 参数2:value , 参数2:有效时间 ;如果存在则抛出异常
	Add(string, interface{}, time.Duration) error

	// 修改值 参数1:key  , 参数2:value , 参数2:有效时间 ; 如果存在则修改,不存在则抛出异常
	Replace(string, interface{}, time.Duration) error

	// 获取值 参数:key
	Get(string, interface{}) (interface{}, error)

	// 清空所有缓存
	Flush()

	// 删除某个缓存
	Delete(string) error

	// 判断键值是否存在
	Has(string) bool
}

实现缓存的接口 接口

type Item

type Item struct {
	// 值
	Value interface{}
	// 过期时间
	Expire int64
}

缓存item值

Jump to

Keyboard shortcuts

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