cache

package
v1.9.5 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CacheMap = sync.Map{}
View Source
var HitCounts = sync.Map{}

Functions

func CleanExpiredCache

func CleanExpiredCache()

定时清理过期缓存

func ClearCache

func ClearCache() error

清空缓存

func DeleteCache

func DeleteCache(key string) error

删除缓存

func GetCacheValue added in v1.8.6

func GetCacheValue[T any](key string) (T, time.Time)

获取缓存值的泛型方法

func GetCurrentGroup

func GetCurrentGroup() int

func LoadCacheFromDB

func LoadCacheFromDB()

从数据库加载缓存

func SetCache

func SetCache(key string, data interface{}, expir time.Time)

设置缓存

func SetCurrentGroup

func SetCurrentGroup(group int)

func UpdateHitCounts

func UpdateHitCounts()

更新命中次数

Types

type CacheItem

type CacheItem struct {
	Key       string    `gorm:"primaryKey"`
	Group     int       `gorm:"column:group" json:"Group" form:"Group" comment:"Group"`
	Data      []byte    `gorm:"column:data" json:"Data" form:"Data" comment:"Data"`
	Expir     time.Time `gorm:"column:expir" json:"Expir" form:"Expir" comment:"Expir"`
	HitCount  int       `gorm:"column:hit_count" json:"HitCount" form:"HitCount" comment:"HitCount"`
	CreatedAt time.Time `gorm:"column:created_at" json:"CreatedAt" form:"CreatedAt" comment:"CreatedAt"`
}

定义缓存项的结构体

func GetCache

func GetCache(key string) *CacheItem

获取缓存

func GetCacheByGroup

func GetCacheByGroup(group int) []*CacheItem

获取指定组的缓存项

type UserInfo

type UserInfo struct {
	Id      int64
	Account string
	RoleIds string
	Permits []string
}

Jump to

Keyboard shortcuts

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