2026-04-02 00:31:28 +08:00
|
|
|
package cache
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"errors"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var ErrNotFound = errors.New("cache: key not found")
|
|
|
|
|
|
2026-05-03 02:02:39 +08:00
|
|
|
type Item struct {
|
|
|
|
|
Key string
|
|
|
|
|
Value []byte
|
|
|
|
|
TTL time.Duration
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-02 00:31:28 +08:00
|
|
|
type Cache interface {
|
|
|
|
|
Get(ctx context.Context, key string) ([]byte, error)
|
2026-05-03 02:02:39 +08:00
|
|
|
GetMulti(ctx context.Context, keys []string) (map[string][]byte, error)
|
2026-04-02 00:31:28 +08:00
|
|
|
Set(ctx context.Context, key string, value []byte, ttl time.Duration) error
|
2026-05-03 02:02:39 +08:00
|
|
|
SetMulti(ctx context.Context, items []Item) error
|
2026-04-02 00:31:28 +08:00
|
|
|
Delete(ctx context.Context, key string) error
|
2026-05-03 02:02:39 +08:00
|
|
|
DeleteMany(ctx context.Context, keys []string) error
|
2026-04-15 16:11:05 +08:00
|
|
|
DeletePrefix(ctx context.Context, prefix string) error
|
2026-04-02 00:31:28 +08:00
|
|
|
}
|