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