mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-05-13 15:12:09 +08:00
[优化] 优化缓存
This commit is contained in:
33
pkg/cache/device_etoken.go
vendored
Normal file
33
pkg/cache/device_etoken.go
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/PandaXGO/PandaKit/rediscli"
|
||||
"time"
|
||||
)
|
||||
|
||||
var RedisDb *rediscli.RedisDB
|
||||
|
||||
// SetDeviceEtoken key 是设备的时候为token, 是子设备的时候为设备编码
|
||||
func SetDeviceEtoken(key string, value any, duration time.Duration) error {
|
||||
return RedisDb.Set(key, value, duration)
|
||||
}
|
||||
|
||||
// GetDeviceEtoken value 是参数指针
|
||||
func GetDeviceEtoken(key string, value interface{}) error {
|
||||
return RedisDb.Get(key, value)
|
||||
}
|
||||
|
||||
// DelDeviceEtoken 删除指定的key
|
||||
func DelDeviceEtoken(key string) error {
|
||||
return RedisDb.Del(context.Background(), key).Err()
|
||||
}
|
||||
|
||||
func ExistsDeviceEtoken(key string) bool {
|
||||
exists, _ := RedisDb.Exists(RedisDb.Context(), key).Result()
|
||||
if exists == 1 {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
8
pkg/cache/panel.go
vendored
Normal file
8
pkg/cache/panel.go
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"github.com/PandaXGO/PandaKit/cache"
|
||||
"time"
|
||||
)
|
||||
|
||||
var PanelCache = cache.NewTimedCache(cache.NoExpiration, 600*time.Second)
|
||||
20
pkg/cache/product_rule.go
vendored
Normal file
20
pkg/cache/product_rule.go
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"github.com/PandaXGO/PandaKit/cache"
|
||||
"time"
|
||||
)
|
||||
|
||||
var ProductCache = cache.NewTimedCache(cache.NoExpiration, 24*time.Hour)
|
||||
|
||||
func ComputeIfAbsentProductRule(key string, fun func(any) (any, error)) (any, error) {
|
||||
return ProductCache.ComputeIfAbsent(key, fun)
|
||||
}
|
||||
|
||||
func DelProductRule(key string) {
|
||||
ProductCache.Delete(key)
|
||||
}
|
||||
|
||||
func PutProductRule(key string, data any) {
|
||||
ProductCache.Put(key, data)
|
||||
}
|
||||
Reference in New Issue
Block a user