Documentation
¶
Index ¶
- Constants
- Variables
- func ChangeFloat32(key string, step float32, expire time.Duration) (float32, error)
- func ChangeFloat64(key string, step float64, expire time.Duration) (float64, error)
- func ChangeInt(key string, step int, expire time.Duration) (int, error)
- func ChangeInt32(key string, step int32, expire time.Duration) (int32, error)
- func ChangeInt64(key string, step int64, expire time.Duration) (int64, error)
- func Clear() error
- func Del(keys ...string) error
- func Get(key string) ([]byte, error)
- func GetBool(key string) bool
- func GetBoolD(key string, defaultVal bool) bool
- func GetDuration(key string) time.Duration
- func GetDurationD(key string, defaultVal time.Duration) time.Duration
- func GetFloat32(key string) float32
- func GetFloat32D(key string, defaultVal float32) float32
- func GetFloat64(key string) float64
- func GetFloat64D(key string, defaultVal float64) float64
- func GetIP(key string) net.IP
- func GetIPD(key string, defaultVal net.IP) net.IP
- func GetInt(key string) int
- func GetInt16(key string) int16
- func GetInt16D(key string, defaultVal int16) int16
- func GetInt32(key string) int32
- func GetInt32D(key string, defaultVal int32) int32
- func GetInt64(key string) int64
- func GetInt64D(key string, defaultVal int64) int64
- func GetInt8(key string) int8
- func GetInt8D(key string, defaultVal int8) int8
- func GetIntD(key string, defaultVal int) int
- func GetString(key string) string
- func GetStringD(key string, defaultVal string) string
- func GetTime(key string) time.Time
- func GetTimeD(key string, defaultVal time.Time) time.Time
- func GetTimeMonth(key string) time.Month
- func GetTimeMonthD(key string, defaultVal time.Month) time.Month
- func GetTimeWeekday(key string) time.Weekday
- func GetTimeWeekdayD(key string, defaultVal time.Weekday) time.Weekday
- func GetUint(key string) uint
- func GetUint16(key string) uint16
- func GetUint16D(key string, defaultVal uint16) uint16
- func GetUint32(key string) uint32
- func GetUint32D(key string, defaultVal uint32) uint32
- func GetUint64(key string) uint64
- func GetUint64D(key string, defaultVal uint64) uint64
- func GetUint8(key string) uint8
- func GetUint8D(key string, defaultVal uint8) uint8
- func GetUintD(key string, defaultVal uint) uint
- func Has(key string) bool
- func PluginDo[T any]() *pluginDo[T]
- func PluginDoMemory[T any]() *pluginDo[T]
- func PluginDoRedis[T any]() *pluginDo[T]
- func PluginDoWith[T any](store CacheIO) *pluginDo[T]
- func PluginSet[T comparable]() *pluginSet[T]
- func PluginSetMemory[T comparable]() *pluginSet[T]
- func PluginSetRedis[T comparable]() *pluginSet[T]
- func PluginSetWith[T comparable](store CacheIO) *pluginSet[T]
- func Scan(key string, refVal any) error
- func Set(key string, val any) error
- func SetDefaultMemory(io CacheIO)
- func SetDefaultRedis(io CacheIO)
- func SetDefaultStoreType(t StoreType)
- func SetExpire(key string, val any, expire time.Duration) error
- func SetJsoner(lib JsonerAPI)
- func SetLogger(log *slog.Logger)
- func SetNotExist(key string, val any, expire time.Duration) error
- func Size() int64
- func UseJsonIterator()
- func UseStandardLibrary()
- type CacheIO
- type JsonerAPI
- type MemoryCache
- func (s *MemoryCache) ChangeFloat32(key string, step float32, expire time.Duration) (float32, error)
- func (s *MemoryCache) ChangeFloat64(key string, step float64, expire time.Duration) (float64, error)
- func (s *MemoryCache) ChangeInt(key string, step int, expire time.Duration) (int, error)
- func (s *MemoryCache) ChangeInt32(key string, step int32, expire time.Duration) (int32, error)
- func (s *MemoryCache) ChangeInt64(key string, step int64, expire time.Duration) (int64, error)
- func (s *MemoryCache) Clear() error
- func (s *MemoryCache) Del(keys ...string) error
- func (s *MemoryCache) Get(key string) ([]byte, error)
- func (s *MemoryCache) GetBool(key string) bool
- func (s *MemoryCache) GetBoolD(key string, defaultVal bool) bool
- func (s *MemoryCache) GetDuration(key string) time.Duration
- func (s *MemoryCache) GetDurationD(key string, defaultVal time.Duration) time.Duration
- func (s *MemoryCache) GetFloat32(key string) float32
- func (s *MemoryCache) GetFloat32D(key string, defaultVal float32) float32
- func (s *MemoryCache) GetFloat64(key string) float64
- func (s *MemoryCache) GetFloat64D(key string, defaultVal float64) float64
- func (s *MemoryCache) GetIP(key string) net.IP
- func (s *MemoryCache) GetIPD(key string, defaultVal net.IP) net.IP
- func (s *MemoryCache) GetInt(key string) int
- func (s *MemoryCache) GetInt16(key string) int16
- func (s *MemoryCache) GetInt16D(key string, defaultVal int16) int16
- func (s *MemoryCache) GetInt32(key string) int32
- func (s *MemoryCache) GetInt32D(key string, defaultVal int32) int32
- func (s *MemoryCache) GetInt64(key string) int64
- func (s *MemoryCache) GetInt64D(key string, defaultVal int64) int64
- func (s *MemoryCache) GetInt8(key string) int8
- func (s *MemoryCache) GetInt8D(key string, defaultVal int8) int8
- func (s *MemoryCache) GetIntD(key string, defaultVal int) int
- func (s *MemoryCache) GetString(key string) string
- func (s *MemoryCache) GetStringD(key string, defaultVal string) string
- func (s *MemoryCache) GetTime(key string) time.Time
- func (s *MemoryCache) GetTimeD(key string, defaultVal time.Time) time.Time
- func (s *MemoryCache) GetTimeMonth(key string) time.Month
- func (s *MemoryCache) GetTimeMonthD(key string, defaultVal time.Month) time.Month
- func (s *MemoryCache) GetTimeWeekday(key string) time.Weekday
- func (s *MemoryCache) GetTimeWeekdayD(key string, defaultVal time.Weekday) time.Weekday
- func (s *MemoryCache) GetUint(key string) uint
- func (s *MemoryCache) GetUint16(key string) uint16
- func (s *MemoryCache) GetUint16D(key string, defaultVal uint16) uint16
- func (s *MemoryCache) GetUint32(key string) uint32
- func (s *MemoryCache) GetUint32D(key string, defaultVal uint32) uint32
- func (s *MemoryCache) GetUint64(key string) uint64
- func (s *MemoryCache) GetUint64D(key string, defaultVal uint64) uint64
- func (s *MemoryCache) GetUint8(key string) uint8
- func (s *MemoryCache) GetUint8D(key string, defaultVal uint8) uint8
- func (s *MemoryCache) GetUintD(key string, defaultVal uint) uint
- func (s *MemoryCache) Has(key string) bool
- func (s *MemoryCache) IsGlobal() bool
- func (s *MemoryCache) Scan(key string, refVal any) error
- func (s *MemoryCache) Set(key string, val any) error
- func (s *MemoryCache) SetExpire(key string, val any, expire time.Duration) error
- func (s *MemoryCache) SetNotExist(key string, val any, expire time.Duration) error
- func (s *MemoryCache) Size() int64
- func (s *MemoryCache) Stats() StoreStats
- func (s *MemoryCache) StoreType() StoreType
- func (s *MemoryCache) TTL(key string) (time.Duration, error)
- func (s *MemoryCache) Tags(tags ...string) TagsIO
- type MemoryOptions
- type RedisCache
- func (s *RedisCache) ChangeFloat32(key string, step float32, expire time.Duration) (float32, error)
- func (s *RedisCache) ChangeFloat64(key string, step float64, expire time.Duration) (float64, error)
- func (s *RedisCache) ChangeInt(key string, step int, expire time.Duration) (int, error)
- func (s *RedisCache) ChangeInt32(key string, step int32, expire time.Duration) (int32, error)
- func (s *RedisCache) ChangeInt64(key string, step int64, expire time.Duration) (int64, error)
- func (s *RedisCache) Clear() error
- func (s *RedisCache) Del(keys ...string) error
- func (s *RedisCache) Get(key string) ([]byte, error)
- func (s *RedisCache) GetBool(key string) bool
- func (s *RedisCache) GetBoolD(key string, defaultVal bool) bool
- func (s *RedisCache) GetDuration(key string) time.Duration
- func (s *RedisCache) GetDurationD(key string, defaultVal time.Duration) time.Duration
- func (s *RedisCache) GetFloat32(key string) float32
- func (s *RedisCache) GetFloat32D(key string, defaultVal float32) float32
- func (s *RedisCache) GetFloat64(key string) float64
- func (s *RedisCache) GetFloat64D(key string, defaultVal float64) float64
- func (s *RedisCache) GetIP(key string) net.IP
- func (s *RedisCache) GetIPD(key string, defaultVal net.IP) net.IP
- func (s *RedisCache) GetInt(key string) int
- func (s *RedisCache) GetInt16(key string) int16
- func (s *RedisCache) GetInt16D(key string, defaultVal int16) int16
- func (s *RedisCache) GetInt32(key string) int32
- func (s *RedisCache) GetInt32D(key string, defaultVal int32) int32
- func (s *RedisCache) GetInt64(key string) int64
- func (s *RedisCache) GetInt64D(key string, defaultVal int64) int64
- func (s *RedisCache) GetInt8(key string) int8
- func (s *RedisCache) GetInt8D(key string, defaultVal int8) int8
- func (s *RedisCache) GetIntD(key string, defaultVal int) int
- func (s *RedisCache) GetString(key string) string
- func (s *RedisCache) GetStringD(key string, defaultVal string) string
- func (s *RedisCache) GetTime(key string) time.Time
- func (s *RedisCache) GetTimeD(key string, defaultVal time.Time) time.Time
- func (s *RedisCache) GetTimeMonth(key string) time.Month
- func (s *RedisCache) GetTimeMonthD(key string, defaultVal time.Month) time.Month
- func (s *RedisCache) GetTimeWeekday(key string) time.Weekday
- func (s *RedisCache) GetTimeWeekdayD(key string, defaultVal time.Weekday) time.Weekday
- func (s *RedisCache) GetUint(key string) uint
- func (s *RedisCache) GetUint16(key string) uint16
- func (s *RedisCache) GetUint16D(key string, defaultVal uint16) uint16
- func (s *RedisCache) GetUint32(key string) uint32
- func (s *RedisCache) GetUint32D(key string, defaultVal uint32) uint32
- func (s *RedisCache) GetUint64(key string) uint64
- func (s *RedisCache) GetUint64D(key string, defaultVal uint64) uint64
- func (s *RedisCache) GetUint8(key string) uint8
- func (s *RedisCache) GetUint8D(key string, defaultVal uint8) uint8
- func (s *RedisCache) GetUintD(key string, defaultVal uint) uint
- func (s *RedisCache) Has(key string) bool
- func (s *RedisCache) IsGlobal() bool
- func (s *RedisCache) Scan(key string, refVal any) error
- func (s *RedisCache) Set(key string, val any) error
- func (s *RedisCache) SetExpire(key string, val any, expire time.Duration) error
- func (s *RedisCache) SetNotExist(key string, val any, expire time.Duration) error
- func (s *RedisCache) Size() int64
- func (s *RedisCache) Stats() StoreStats
- func (s *RedisCache) StoreType() StoreType
- func (s *RedisCache) TTL(key string) (time.Duration, error)
- func (s *RedisCache) Tags(tags ...string) TagsIO
- type RedisOptions
- type RedisUniversalOptions
- type StoreStats
- type StoreType
- type TagsIO
Constants ¶
const ( MemoryCacheSizeMin = 10 //单位 MB MemoryCacheSizeDefault = 100 )
Variables ¶
var ( ErrStoreInstanceIsNil = errors.New("cache: store instance is nil") ErrStoreTypeNotExist = errors.New("cache: store type does not exist") ErrKeyCanNotEmpty = errors.New("cache: key can not empty") ErrKeyNotExist = errors.New("cache: key does not exist") ErrValNotExist = errors.New("cache: val does not exist") ErrTagCanNotEmpty = errors.New("cache: tag can not empty") ErrTagNotExist = errors.New("cache: tag does not exist") ErrTagKeyNotExist = errors.New("cache: tag/key does not exist") ErrValIsNilPointer = errors.New("cache: val can not a nil pointer") ErrValNotMarshal = errors.New("cache: val does not Marshal") ErrValNotUnmarshal = errors.New("cache: val does not Unmarshal") )
Functions ¶
func ChangeFloat32 ¶
ChangeFloat32 自增自减更新缓存(步进值为正数表示自增,步进值为负数表示自减)
- expire 过期时间,如key存在则继续沿用原有过期时间,如key不存在则存储并设置过期时间
func ChangeFloat64 ¶
ChangeFloat64 自增自减更新缓存(步进值为正数表示自增,步进值为负数表示自减)
- expire 过期时间,如key存在则继续沿用原有过期时间,如key不存在则存储并设置过期时间
func ChangeInt ¶
ChangeInt 自增自减更新缓存(步进值为正数表示自增,步进值为负数表示自减)
- expire 过期时间,如key存在则继续沿用原有过期时间,如key不存在则存储并设置过期时间
func ChangeInt32 ¶
ChangeInt32 自增自减更新缓存(步进值为正数表示自增,步进值为负数表示自减)
- expire 过期时间,如key存在则继续沿用原有过期时间,如key不存在则存储并设置过期时间
func ChangeInt64 ¶
ChangeInt64 自增自减更新缓存(步进值为正数表示自增,步进值为负数表示自减)
- expire 过期时间,如key存在则继续沿用原有过期时间,如key不存在则存储并设置过期时间
func Get ¶
Get returns the value for the given key, ie: ([]byte, nil). If the value does not exists it returns (nil, error)
func GetFloat32D ¶
GetFloat32Default 读取 FLOAT32 If the value does not exists it return defaultVal
func GetFloat64D ¶
GetFloat64Default 读取 FLOAT64 If the value does not exists it return defaultVal
func GetStringD ¶
GetStringDefault 读取 String If the value does not exists it return defaultVal
func GetTimeMonth ¶
func GetTimeWeekday ¶
func GetUint16D ¶
GetUint16Default 读取 UINT8 If the value does not exists it return defaultVal
func GetUint32D ¶
GetUint32Default 读取 UINT32 If the value does not exists it return defaultVal
func GetUint64D ¶
GetUint64Default 读取 UINT64 If the value does not exists it return defaultVal
func PluginDo ¶
func PluginDo[T any]() *pluginDo[T]
PluginDo 获取一个缓存自动初始化回调缓存包装接口 ( 使用默认 DefaultStore 实例 )
func PluginDoMemory ¶ added in v1.1.0
func PluginDoMemory[T any]() *pluginDo[T]
PluginDoMemory 获取一个缓存自动初始化回调缓存包装接口 ( 使用默认 StoreMemory 实例 )
func PluginDoRedis ¶ added in v1.1.0
func PluginDoRedis[T any]() *pluginDo[T]
PluginDoRedis 获取一个缓存自动初始化回调缓存包装接口 ( 使用默认 StoreRedis 实例 )
func PluginDoWith ¶ added in v1.1.0
PluginDoWith 获取一个缓存自动初始化回调缓存包装接口 ( 使用指定 Store CacheIO 实例 )
func PluginSet ¶
func PluginSet[T comparable]() *pluginSet[T]
PluginSet 获取一个缓存泛型化集合插件实例 ( 使用默认 Store 实例 )
func PluginSetMemory ¶ added in v1.1.0
func PluginSetMemory[T comparable]() *pluginSet[T]
PluginSetMemory 获取一个缓存泛型化集合插件实例 ( 使用默认 StoreMemory 实例 )
func PluginSetRedis ¶ added in v1.1.0
func PluginSetRedis[T comparable]() *pluginSet[T]
PluginSetRedis 获取一个缓存泛型化集合插件实例 ( 使用默认 StoreRedis 实例 )
func PluginSetWith ¶ added in v1.1.0
func PluginSetWith[T comparable](store CacheIO) *pluginSet[T]
PluginSetWith 获取一个缓存泛型化集合插件实例 ( 使用指定 Store CacheIO 实例 )
func Scan ¶
Scan 方式获取缓存对象,适用于 Slice/Map/Struct 缓存对象, 反序列化扫描后放入引用地址变量 注意: 不建议直接获取任何非基本类型的缓存进行断言转换,Cache 驱动为Memory时工作正常,如为Redis则无法转换
func SetDefaultMemory ¶ added in v1.1.0
func SetDefaultMemory(io CacheIO)
SetDefaultMemory 设置全局默认StoreMemory缓存实例
func SetDefaultRedis ¶ added in v1.1.0
func SetDefaultRedis(io CacheIO)
SetDefaultRedis 设置全局默认StoreRedis缓存实例
func SetDefaultStoreType ¶ added in v1.1.0
func SetDefaultStoreType(t StoreType)
SetDefaultStoreType 设置默认缓存仓库的驱动类型 StoreType
func SetNotExist ¶
SetNotExist 设置缓存(标记过期时间,为0表示永不过期),不存在则设置
func UseJsonIterator ¶ added in v1.1.0
func UseJsonIterator()
UseJsonIterator 切换Json库为 Json Iterator 库
func UseStandardLibrary ¶ added in v1.1.0
func UseStandardLibrary()
UseStandardLibrary 切换Json库为 Json StandardLibrary 标准库
Types ¶
type CacheIO ¶
type CacheIO interface { //Has 判断缓存是否存在 Has(key string) bool //TTL 获取缓存过期时间 (返回0 表示不过期(实例生命周期内/长久存储) 注意:最小过期时间为1s time.Second) TTL(key string) (time.Duration, error) //Get 读取缓存 Get(key string) (val []byte, err error) GetString(key string) string GetStringD(key string, defaultVal string) string GetInt(key string) int GetIntD(key string, defaultVal int) int GetInt8(key string) int8 GetInt8D(key string, defaultVal int8) int8 GetInt16(key string) int16 GetInt16D(key string, defaultVal int16) int16 GetInt32(key string) int32 GetInt32D(key string, defaultVal int32) int32 GetInt64(key string) int64 GetInt64D(key string, defaultVal int64) int64 GetUint(key string) uint GetUintD(key string, defaultVal uint) uint GetUint8(key string) uint8 GetUint8D(key string, defaultVal uint8) uint8 GetUint16(key string) uint16 GetUint16D(key string, defaultVal uint16) uint16 GetUint32(key string) uint32 GetUint32D(key string, defaultVal uint32) uint32 GetUint64(key string) uint64 GetUint64D(key string, defaultVal uint64) uint64 GetFloat32(key string) float32 GetFloat32D(key string, defaultVal float32) float32 GetFloat64(key string) float64 GetFloat64D(key string, defaultVal float64) float64 GetBool(key string) bool GetBoolD(key string, defaultVal bool) bool GetTime(key string) time.Time GetTimeD(key string, defaultVal time.Time) time.Time GetDuration(key string) time.Duration GetDurationD(key string, defaultVal time.Duration) time.Duration GetTimeMonth(key string) time.Month GetTimeMonthD(key string, defaultVal time.Month) time.Month GetTimeWeekday(key string) time.Weekday GetTimeWeekdayD(key string, defaultVal time.Weekday) time.Weekday GetIP(key string) net.IP GetIPD(key string, defaultVal net.IP) net.IP // Scan 方式获取缓存对象,适用于 Slice/Map/Struct 缓存对象, 反序列化扫描后放入引用地址变量 Scan(key string, refVal any) error // Set 设置缓存(默认过期时间) Set(key string, val any) error // SetExpire 设置缓存(标记过期时间,为0表示永不过期) , 注意:最小过期时间为 1s => time.Second SetExpire(key string, val any, expire time.Duration) error // SetNotExist 设置缓存(标记过期时间,为0表示永不过期),不存在则设置 SetNotExist(key string, val any, expire time.Duration) error // ChangeInt 自增自减更新缓存(步进值为正数表示自增,步进值为负数表示自减) 标记过期时间,为0表示永不过期 // - expire 过期时间,如key存在则继续沿用原有过期时间,如key不存在则存储并设置过期时间 ChangeInt(key string, step int, expire time.Duration) (newVal int, err error) // ChangeInt32 自增自减更新缓存(步进值为正数表示自增,步进值为负数表示自减) 标记过期时间,为0表示永不过期 // - expire 过期时间,如key存在则继续沿用原有过期时间,如key不存在则存储并设置过期时间 ChangeInt32(key string, step int32, expire time.Duration) (newVal int32, err error) // ChangeInt64 自增自减更新缓存(步进值为正数表示自增,步进值为负数表示自减) 标记过期时间,为0表示永不过期 // - expire 过期时间,如key存在则继续沿用原有过期时间,如key不存在则存储并设置过期时间 ChangeInt64(key string, step int64, expire time.Duration) (newVal int64, err error) // ChangeFloat32 自增自减更新缓存(步进值为正数表示自增,步进值为负数表示自减) 标记过期时间,为0表示永不过期 // - expire 过期时间,如key存在则继续沿用原有过期时间,如key不存在则存储并设置过期时间 ChangeFloat32(key string, step float32, expire time.Duration) (newVal float32, err error) // ChangeFloat64 自增自减更新缓存(步进值为正数表示自增,步进值为负数表示自减) 标记过期时间,为0表示永不过期 // - expire 过期时间,如key存在则继续沿用原有过期时间,如key不存在则存储并设置过期时间 ChangeFloat64(key string, step float64, expire time.Duration) (newVal float64, err error) //Del 删除缓存 Del(keys ...string) error //Clear 清空全部缓存 Clear() error //Size 获取已缓存数据的条目 Size() int64 //StoreType 获取缓存库的类型 StoreType() StoreType //Tags 指定缓存标签 Tags(tags ...string) TagsIO //Stats 获取性能指标统计信息 Stats() StoreStats // 判断当且Cache是否为全局默认实例 IsGlobal() bool // contains filtered or unexported methods }
func GetDefault ¶ added in v1.1.0
func GetDefault() CacheIO
GetDefault 获取默认缓存实例 StoreIO
- 如果默认实例未配置(未初始化),将自动尝试使用默认参数进行初始化
- 用户可通过 `SetDefaultStoreType` 设置默认缓存实例的 StoreType 驱动类型(默认为 StoreMemory)
- 用户可通过 `SetDefaultMemory` 设置自定义默认 StoreMemory 缓存实例
- 用户可通过 `SetDefaultRedis` 设置自定义默认 StoreRedis 缓存实例
func GetDefaultMemory ¶ added in v1.1.0
func GetDefaultMemory() CacheIO
GetDefaultMemory 获取全局默认 StoreMemory 缓存实例
- 用户可通过 `SetDefaultMemory` 设置自定义默认 StoreMemory 缓存实例
- 如果默认实例未配置(未初始化),会尝试使用默认参数自动延迟初始化
func GetDefaultRedis ¶ added in v1.1.0
func GetDefaultRedis() CacheIO
GetDefaultRedis 全局StoreRedis缓存
- 用户可通过 `SetDefaultRedis` 设置自定义默认 StoreRedis 缓存实例
- 如果默认实例未配置(未初始化),会尝试使用默认参数自动延迟初始化
type JsonerAPI ¶
type JsonerAPI interface { // Marshal adapts to json/encoding Marshal API // Refer to https://godoc.org/encoding/json#Marshal for more information Marshal(v any) ([]byte, error) // Unmarshal adapts to json/encoding Unmarshal API // Refer to https://godoc.org/encoding/json#Unmarshal for more information Unmarshal(data []byte, v any) error // Valid reports whether data is a valid JSON encoding Valid(v []byte) bool }
type MemoryCache ¶
type MemoryCache struct {
// contains filtered or unexported fields
}
func NewMemory ¶
func NewMemory(options MemoryOptions) (*MemoryCache, error)
func (*MemoryCache) ChangeFloat32 ¶
func (s *MemoryCache) ChangeFloat32(key string, step float32, expire time.Duration) (float32, error)
ChangeFloat32 自增自减更新缓存(步进值为正数表示自增,步进值为负数表示自减)
- expire 过期时间,如key存在则继续沿用原有过期时间,如key不存在则存储并设置过期时间
func (*MemoryCache) ChangeFloat64 ¶
func (s *MemoryCache) ChangeFloat64(key string, step float64, expire time.Duration) (float64, error)
ChangeFloat64 自增自减更新缓存(步进值为正数表示自增,步进值为负数表示自减)
- expire 过期时间,如key存在则继续沿用原有过期时间,如key不存在则存储并设置过期时间
func (*MemoryCache) ChangeInt ¶
ChangeInt 自增自减更新缓存(步进值为正数表示自增,步进值为负数表示自减)
- expire 过期时间,如key存在则继续沿用原有过期时间,如key不存在则存储并设置过期时间
func (*MemoryCache) ChangeInt32 ¶
ChangeInt32 自增自减更新缓存(步进值为正数表示自增,步进值为负数表示自减)
- expire 过期时间,如key存在则继续沿用原有过期时间,如key不存在则存储并设置过期时间
func (*MemoryCache) ChangeInt64 ¶
ChangeInt64 自增自减更新缓存(步进值为正数表示自增,步进值为负数表示自减)
- expire 过期时间,如key存在则继续沿用原有过期时间,如key不存在则存储并设置过期时间
func (*MemoryCache) Get ¶
func (s *MemoryCache) Get(key string) ([]byte, error)
Get returns the value for the given key, ie: ([]byte, nil). If the value does not exists it returns (nil, error)
func (*MemoryCache) GetBoolD ¶
func (s *MemoryCache) GetBoolD(key string, defaultVal bool) bool
GetBoolDefault 读取 BOOL If the value does not exists it return defaultVal
func (*MemoryCache) GetDuration ¶
func (s *MemoryCache) GetDuration(key string) time.Duration
GetDuration time.Duration => int64
func (*MemoryCache) GetDurationD ¶
GetDurationD
func (*MemoryCache) GetFloat32 ¶
func (s *MemoryCache) GetFloat32(key string) float32
GetFloat32 读取 FLOAT32
func (*MemoryCache) GetFloat32D ¶
func (s *MemoryCache) GetFloat32D(key string, defaultVal float32) float32
GetFloat32Default 读取 FLOAT32 If the value does not exists it return defaultVal
func (*MemoryCache) GetFloat64 ¶
func (s *MemoryCache) GetFloat64(key string) float64
GetFloat64 读取 FLOAT64
func (*MemoryCache) GetFloat64D ¶
func (s *MemoryCache) GetFloat64D(key string, defaultVal float64) float64
GetFloat64Default 读取 FLOAT64 If the value does not exists it return defaultVal
func (*MemoryCache) GetInt16D ¶
func (s *MemoryCache) GetInt16D(key string, defaultVal int16) int16
GetInt16Default 读取 INT16 If the value does not exists it return defaultVal
func (*MemoryCache) GetInt32D ¶
func (s *MemoryCache) GetInt32D(key string, defaultVal int32) int32
GetInt32Default 读取 INT32 If the value does not exists it return defaultVal
func (*MemoryCache) GetInt64D ¶
func (s *MemoryCache) GetInt64D(key string, defaultVal int64) int64
GetInt64Default 读取 INT64 If the value does not exists it return defaultVal
func (*MemoryCache) GetInt8D ¶
func (s *MemoryCache) GetInt8D(key string, defaultVal int8) int8
GetInt8Default 读取 INT8 If the value does not exists it return defaultVal
func (*MemoryCache) GetIntD ¶
func (s *MemoryCache) GetIntD(key string, defaultVal int) int
GetIntDefault 读取 INT If the value does not exists it return defaultVal
func (*MemoryCache) GetString ¶
func (s *MemoryCache) GetString(key string) string
GetString 读取 String
func (*MemoryCache) GetStringD ¶
func (s *MemoryCache) GetStringD(key string, defaultVal string) string
GetStringDefault 读取 String If the value does not exists it return defaultVal
func (*MemoryCache) GetTimeMonth ¶
func (s *MemoryCache) GetTimeMonth(key string) time.Month
GetTimeMonth time.Month => int
func (*MemoryCache) GetTimeMonthD ¶
GetTimeMonthD
func (*MemoryCache) GetTimeWeekday ¶
func (s *MemoryCache) GetTimeWeekday(key string) time.Weekday
GetTimeWeekday
func (*MemoryCache) GetTimeWeekdayD ¶
GetTimeWeekdayD
func (*MemoryCache) GetUint16 ¶
func (s *MemoryCache) GetUint16(key string) uint16
GetUint16 读取 UINT8
func (*MemoryCache) GetUint16D ¶
func (s *MemoryCache) GetUint16D(key string, defaultVal uint16) uint16
GetUint16Default 读取 UINT8 If the value does not exists it return defaultVal
func (*MemoryCache) GetUint32 ¶
func (s *MemoryCache) GetUint32(key string) uint32
GetUint32 读取 UINT32
func (*MemoryCache) GetUint32D ¶
func (s *MemoryCache) GetUint32D(key string, defaultVal uint32) uint32
GetUint32Default 读取 UINT32 If the value does not exists it return defaultVal
func (*MemoryCache) GetUint64 ¶
func (s *MemoryCache) GetUint64(key string) uint64
GetUint64 读取 UINT64
func (*MemoryCache) GetUint64D ¶
func (s *MemoryCache) GetUint64D(key string, defaultVal uint64) uint64
GetUint64Default 读取 UINT64 If the value does not exists it return defaultVal
func (*MemoryCache) GetUint8D ¶
func (s *MemoryCache) GetUint8D(key string, defaultVal uint8) uint8
GetUint8Default 读取 UINT8 If the value does not exists it return defaultVal
func (*MemoryCache) GetUintD ¶
func (s *MemoryCache) GetUintD(key string, defaultVal uint) uint
GetUintDefault 读取 UINT If the value does not exists it return defaultVal
func (*MemoryCache) IsGlobal ¶ added in v1.1.0
func (s *MemoryCache) IsGlobal() bool
判断当且Cache是否为全局默认实例
func (*MemoryCache) Scan ¶
func (s *MemoryCache) Scan(key string, refVal any) error
Scan 方式获取缓存对象,适用于 Slice/Map/Struct 缓存对象, 反序列化扫描后放入引用地址变量 注意: 不建议直接获取任何非基本类型的缓存进行断言转换,Cache 驱动为Memory时工作正常,如为Redis则无法转换
func (*MemoryCache) SetNotExist ¶
SetNotExist 设置缓存(标记过期时间,为0表示永不过期),不存在则设置
func (*MemoryCache) StoreType ¶
func (s *MemoryCache) StoreType() StoreType
type MemoryOptions ¶
type MemoryOptions struct { // CacheSize MemoryCache 占用内存大小, 单位MB, 默认 100M,最小10M // - MemoryCache底层由freecache驱动, 每个freecache有256个segment,因此每个缓存[entry]大小不能超过 freecache内存大小的1/1024 CacheSize int // DefaultExpire 默认过期时间(配置单位为[秒]) 0 表示不过期(实例生命周期内/长久存储) 注意:最小过期时间为1s time.Second // FreeCache 的过期时间是一个近似值,实际过期时间会在 (X-1, X] 秒之间,其中 X 是你设置的过期时间。 DefaultExpire int }
type RedisCache ¶
type RedisCache struct {
// contains filtered or unexported fields
}
func NewRedis ¶
func NewRedis(options RedisOptions) (*RedisCache, error)
NewRedis
- options RedisOptions
func (*RedisCache) ChangeFloat32 ¶
ChangeFloat32 自增自减更新缓存(步进值为正数表示自增,步进值为负数表示自减)
- expire 过期时间,如key存在则继续沿用原有过期时间,如key不存在则存储并设置过期时间
func (*RedisCache) ChangeFloat64 ¶
ChangeFloat64 自增自减更新缓存(步进值为正数表示自增,步进值为负数表示自减)
- expire 过期时间,如key存在则继续沿用原有过期时间,如key不存在则存储并设置过期时间
func (*RedisCache) ChangeInt ¶
ChangeInt 自增自减更新缓存(步进值为正数表示自增,步进值为负数表示自减)
- expire 过期时间,如key存在则继续沿用原有过期时间,如key不存在则存储并设置过期时间
func (*RedisCache) ChangeInt32 ¶
ChangeInt32 自增自减更新缓存(步进值为正数表示自增,步进值为负数表示自减)
- expire 过期时间,如key存在则继续沿用原有过期时间,如key不存在则存储并设置过期时间
func (*RedisCache) ChangeInt64 ¶
ChangeInt64 自增自减更新缓存(步进值为正数表示自增,步进值为负数表示自减)
- expire 过期时间,如key存在则继续沿用原有过期时间,如key不存在则存储并设置过期时间
func (*RedisCache) Get ¶
func (s *RedisCache) Get(key string) ([]byte, error)
Get returns the value for the given key, ie: ([]byte, nil). If the value does not exists it returns (nil, error)
func (*RedisCache) GetDuration ¶
func (s *RedisCache) GetDuration(key string) time.Duration
GetDuration time.Duration => int64
func (*RedisCache) GetDurationD ¶
func (*RedisCache) GetFloat32D ¶
func (s *RedisCache) GetFloat32D(key string, defaultVal float32) float32
func (*RedisCache) GetFloat64D ¶
func (s *RedisCache) GetFloat64D(key string, defaultVal float64) float64
func (*RedisCache) GetStringD ¶
func (s *RedisCache) GetStringD(key string, defaultVal string) string
func (*RedisCache) GetTimeMonth ¶
func (s *RedisCache) GetTimeMonth(key string) time.Month
GetTimeMonth time.Month => int
func (*RedisCache) GetTimeMonthD ¶
GetTimeMonthD
func (*RedisCache) GetTimeWeekday ¶
func (s *RedisCache) GetTimeWeekday(key string) time.Weekday
GetTimeWeekday
func (*RedisCache) GetTimeWeekdayD ¶
GetTimeWeekdayD
func (*RedisCache) GetUint16D ¶
func (s *RedisCache) GetUint16D(key string, defaultVal uint16) uint16
func (*RedisCache) GetUint32D ¶
func (s *RedisCache) GetUint32D(key string, defaultVal uint32) uint32
func (*RedisCache) GetUint64D ¶
func (s *RedisCache) GetUint64D(key string, defaultVal uint64) uint64
func (*RedisCache) IsGlobal ¶ added in v1.1.0
func (s *RedisCache) IsGlobal() bool
判断当且Cache是否为全局默认实例
func (*RedisCache) Scan ¶
func (s *RedisCache) Scan(key string, refVal any) error
Scan 方式获取缓存对象,适用于 Slice/Map/Struct 缓存对象, 反序列化扫描后放入引用地址变量
func (*RedisCache) SetNotExist ¶
SetNotExist 设置缓存(标记过期时间,为0表示永不过期),不存在则设置
func (*RedisCache) StoreType ¶
func (s *RedisCache) StoreType() StoreType
type RedisOptions ¶
type RedisOptions struct { // Client Redis服务器链接选项,使用 UniversalClient 统一客户端,UniversalClient是对 Client 、 ClusterClient 、 FailoverClient 客户端的包装。 // - 根据不同的选项,客户端的类型如下: // - 如果指定了 MasterName 选项,则返回 FailoverClient 哨兵客户端。 // - 如果 Addrs 是 2 个以上的地址,则返回 ClusterClient 集群客户端。 // - 其他情况,返回 Client 单节点客户端。 // - github.com/redis/go-redis/v9 // - https://redis.uptrace.dev/zh/guide/universal.html // - RedisUniversalOptions is an alias for [redis.UniversalOptions] Client RedisUniversalOptions // DefaultExpire 默认过期时间(配置单位为[秒]) 0 表示不过期(实例生命周期内/长久存储) 注意:最小过期时间为1s time.Second // FreeCache 的过期时间是一个近似值,实际过期时间会在 (X-1, X] 秒之间,其中 X 是你设置的过期时间。 DefaultExpire int }
RedisOptions Redis缓存配置信息
type RedisUniversalOptions ¶ added in v1.1.0
type RedisUniversalOptions = redis.UniversalOptions
type StoreStats ¶
type StoreType ¶
type StoreType = string
func GetDefaultStoreType ¶ added in v1.1.0
func GetDefaultStoreType() StoreType
GetDefaultStoreType 获取默认缓存仓库的驱动类型 StoreType
type TagsIO ¶
type TagsIO interface { // Set 指定Tags下设置缓存(默认过期时间) Set(key string, val any) error // SetExpire 指定Tags下设置缓存(标记过期时间,为0表示永不过期) , 注意:最小过期时间为1s time.Second SetExpire(key string, val any, expire time.Duration) error // SetNotExist 指定Tags下设置缓存(标记过期时间,为0表示永不过期),不存在则设置 , 注意:最小过期时间为1s time.Second SetNotExist(key string, val any, expire time.Duration) error //Del 删除指定Tags下的缓存 Del(keys ...string) error //Clear 清空指定Tags下的全部缓存 Clear() error //Size 获取指定Tags下缓存数据的条目 Size() int64 }