2023-02-02 11:16:18 +00:00
|
|
|
package cache
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-12-26 15:09:30 +00:00
|
|
|
"sync"
|
2023-02-02 11:16:18 +00:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Cache[K comparable, V any] interface {
|
|
|
|
Get(ctx context.Context, key K) (V, bool)
|
2023-10-27 12:51:46 +00:00
|
|
|
Set(ctx context.Context, key K, val V)
|
|
|
|
GetExpireTime(ctx context.Context) time.Duration
|
|
|
|
Ttl(ctx context.Context, key K) time.Duration
|
2023-02-02 11:16:18 +00:00
|
|
|
Flush(ctx context.Context)
|
2023-10-27 12:51:46 +00:00
|
|
|
Del(ctx context.Context, key ...K)
|
|
|
|
ClearExpired(ctx context.Context)
|
2023-02-02 11:16:18 +00:00
|
|
|
}
|
2023-10-29 10:46:01 +00:00
|
|
|
|
|
|
|
type Expend[K comparable, V any] interface {
|
|
|
|
Gets(ctx context.Context, k []K) (map[K]V, error)
|
|
|
|
Sets(ctx context.Context, m map[K]V)
|
|
|
|
}
|
2023-11-02 14:40:13 +00:00
|
|
|
|
|
|
|
type SetTime interface {
|
|
|
|
SetExpiredTime(func() time.Duration)
|
|
|
|
}
|
|
|
|
|
|
|
|
type AnyCache[T any] interface {
|
|
|
|
Get(ctx context.Context) (T, bool)
|
|
|
|
Set(ctx context.Context, v T)
|
|
|
|
Flush(ctx context.Context)
|
|
|
|
GetLastSetTime(ctx context.Context) time.Time
|
|
|
|
}
|
2023-11-28 14:46:22 +00:00
|
|
|
|
|
|
|
type Refresh[K comparable, V any] interface {
|
|
|
|
Refresh(ctx context.Context, k K, a ...any)
|
|
|
|
}
|
2023-11-29 10:24:41 +00:00
|
|
|
type RefreshVar[T any] interface {
|
|
|
|
Refresh(ctx context.Context, a ...any)
|
|
|
|
}
|
2023-12-26 15:09:30 +00:00
|
|
|
|
|
|
|
type Lockss[K comparable] interface {
|
|
|
|
GetLock(ctx context.Context, gMut *sync.Mutex, k ...K) *sync.Mutex
|
|
|
|
}
|
|
|
|
|
|
|
|
type LockFn[K comparable] func(ctx context.Context, gMut *sync.Mutex, k ...K) *sync.Mutex
|
|
|
|
|
|
|
|
type LocksNum interface {
|
|
|
|
SetLockNum(num int)
|
|
|
|
}
|