xcache

package
v0.3.32 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2024 License: BSD-3-Clause-Clear Imports: 9 Imported by: 0

Documentation

Overview

缓存模块

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clear

func Clear() error

清空缓存数据

func Exists

func Exists(keys string) bool

判断变量是否存在

keys	待判断的变量名

func Get

func Get(key string) (string, error)

获取key的值

key	要获取的key下标

func GetString

func GetString(key string) string

获取KEY设置的值

key	要获取的key下标

func GetStruct

func GetStruct(key string, val any) error

读取结构体

key	缓存的key名称
val	预期读取的类型【使用json串行化进行反解析】

func Gkey added in v0.3.25

func Gkey(g string, arg ...any) string

将缓存下标追加到缓存组中,并返回该下标

g	分组名称
arg	任意类型参数,用于进行MD5加密,返回缓存下标信息

func Group added in v0.3.12

func Group(g, key string)

将属性追加到分组中,以便后续的分组清理操作

g	分组名称
key	追加的key列表

func GroupRemove added in v0.3.12

func GroupRemove(g string)

分组清理

g	分组名称

func Key

func Key(args ...any) string

生成CacheKey下标 增强模式,针对多维map进行order排序、string拼接、MD5生成的方式进行保持一致

args	任意类型参数,用于进行MD5加密,返回缓存下标信息

func Remove

func Remove(key string) error

移除缓存下标信息

key	要移除的缓存下标

func Set

func Set(key, val string) error

设置Key的值

key	下标
val	值

func SetDefaultTime added in v0.3.25

func SetDefaultTime(c time.Duration)

设置默认缓存时长

c	默认的缓存时长,默认0-不超时

func SetExt

func SetExt(key, val string, t time.Duration) error

设置Key的值

key	下标
val	值
t	延时删除时间

func SetGroup added in v0.3.25

func SetGroup(child, self int)

设置缓存组中的数量限制

child	分组内列表的最大数量限制
self	外层组数量最大限制

func SetInteface added in v0.3.25

func SetInteface(c CacheInteface)

设置存储驱动 默认使用 sync.Map 进行缓存读写,若无特殊需求,不建议使用此操作迁出缓存操作类

c	存储缓存的驱动标识

func SetNumber

func SetNumber(key string, val any) error

设置数字类型缓存,避免使用时再进行fmt.Sprintf转化(因any类型可能为多种数字类型,所以此处使用fmt进行转化) 使用SetNumber存储,读取时也只能使用GetString进行读取,然后再通过xstring.Toxxxx进行转化【或者使用json.Number进行转化】

key	缓存下标
val	缓存值

func SetStruct

func SetStruct(key string, val any) error

设置结构体

key	缓存的key名称
val	设置的缓存值类型,使用json串行化进行解析存储

func SetStructExt

func SetStructExt(key string, val any, t time.Duration) error

设置结构体

key	缓存的key名称
val	设置的缓存值类型,使用json串行化进行解析存储
t	缓存时间

Types

type CacheInteface added in v0.3.25

type CacheInteface interface {
	Store(name, value string, ext time.Duration) error // 存储缓存信息
	Load(name string) (string, error)                  // 读取缓存信息
	Delete(name string) error                          // 删除缓存信息【会先调用Load判断是否存在,基本不存在删除空数据问题】
	Clear() error                                      // 清空全部缓存
}

基础缓存接口实现

type Config

type Config struct {
	Inteface    CacheInteface // 缓存读写的操作类
	DefaultTime time.Duration // 默认缓存时长 2小时
	CacheSync   sync.Map      // 程序内缓存
	// contains filtered or unexported fields
}

缓存操作配置项信息

Jump to

Keyboard shortcuts

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