feat: upgrade cache

This commit is contained in:
2025-10-18 11:31:47 +08:00
parent eda887e8ff
commit 9f21048ac0
5 changed files with 14 additions and 44 deletions

View File

@ -51,7 +51,7 @@ func (g *Gocache) TTL(ctx context.Context, cacheInstanceFlag string, key string)
return expireAt.Unix() - time.Now().Unix(), nil
}
func (g *Gocache) Set(ctx context.Context, cacheInstanceFlag string, key string, value string, ttl int64) error {
func (g *Gocache) Set(ctx context.Context, cacheInstanceFlag string, key string, value any, ttl int64) error {
now := time.Now()
if now.Unix() < ttl {
ttl = ttl - now.Unix()
@ -60,7 +60,7 @@ func (g *Gocache) Set(ctx context.Context, cacheInstanceFlag string, key string,
return nil
}
func (g *Gocache) Get(ctx context.Context, cacheInstanceFlag string, key string) (string, error) {
func (g *Gocache) Get(ctx context.Context, cacheInstanceFlag string, key string) (any, error) {
val, exist := GocacheStorageClient.Get(cacheInstanceFlag).Get(key)
if !exist {
return "", errors.New(key + " : not found")
@ -68,7 +68,7 @@ func (g *Gocache) Get(ctx context.Context, cacheInstanceFlag string, key string)
return val.(string), nil
}
func (g *Gocache) GetWithParse(ctx context.Context, cacheInstanceFlag string, key string, parseFunc cacheAbstract.ResultParseFunc) (string, error) {
func (g *Gocache) GetWithParse(ctx context.Context, cacheInstanceFlag string, key string, parseFunc cacheAbstract.ResultParseFunc) (any, error) {
val, err := g.Get(ctx, cacheInstanceFlag, key)
if nil != err {
return "", err