kos/pkg/cache/cache.go

19 lines
423 B
Go
Raw Normal View History

2023-04-23 17:57:36 +08:00
package cache
import (
"context"
"time"
)
2023-06-30 14:16:16 +08:00
type (
LoadFunc func(ctx context.Context) (any, error)
)
2023-04-23 17:57:36 +08:00
type Cache interface {
Set(ctx context.Context, key string, value any)
SetEx(ctx context.Context, key string, value any, expire time.Duration)
Get(ctx context.Context, key string) (value any, ok bool)
2023-06-30 14:16:16 +08:00
Try(ctx context.Context, key string, cb LoadFunc) (value any, err error)
2023-04-23 17:57:36 +08:00
Del(ctx context.Context, key string)
}