Documentation ¶
Overview ¶
Package sdcache 缓存工具箱
Index ¶
- Variables
- func DoTestCommon(t *testing.T, c Cache)
- func DoTestExpiration(t *testing.T, c Cache, ttlSecs int64)
- type Cache
- type Double
- func (d Double[L1, L2]) Clear(ctx context.Context) error
- func (d Double[L1, L2]) Delete(ctx context.Context, k any) error
- func (d Double[L1, L2]) Get(ctx context.Context, k any) (any, error)
- func (d Double[L1, L2]) GetOrPut(ctx context.Context, k any, ...) (any, error)
- func (d Double[L1, L2]) GetTTL(ctx context.Context, k any) (time.Duration, error)
- func (d Double[L1, L2]) Put(ctx context.Context, k, v any, opts *PutOptions) error
- type Encoder
- type FuncKey
- type Int64Key
- type JsonEncoder
- type Key
- type PutOptions
- type StrKey
- type TextEncoder
- type Typed
- func (t Typed[K, V]) Clear(ctx context.Context) error
- func (t Typed[K, V]) Delete(ctx context.Context, k K) error
- func (t Typed[K, V]) Get(ctx context.Context, k K) (V, error)
- func (t Typed[K, V]) GetOrPut(ctx context.Context, k K, loader func(ctx context.Context, k K) (V, error), ...) (V, error)
- func (t Typed[K, V]) GetTTL(ctx context.Context, k K) (time.Duration, error)
- func (t Typed[K, V]) Put(ctx context.Context, k K, v V, opts *PutOptions) error
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrNotFound = sderr.Sentinel("cache key not found")
)
Functions ¶
func DoTestCommon ¶
Types ¶
type Cache ¶
type Cache interface { Clear(ctx context.Context) error Get(ctx context.Context, k any) (any, error) GetTTL(ctx context.Context, k any) (time.Duration, error) Put(ctx context.Context, k, v any, opts *PutOptions) error Delete(ctx context.Context, k any) error GetOrPut(ctx context.Context, k any, loader func(ctx context.Context, k any) (any, error), opts *PutOptions) (any, error) }
type Double ¶
type Double[L1, L2 interface { comparable Cache }] struct { L1 L1 L2 L2 }
func D ¶
func D[L1, L2 interface { comparable Cache }](c1 L1, c2 L2) Double[L1, L2]
type FuncKey ¶
type FuncKey struct { Encode func(k any) (string, error) Decode func(s string) (any, error) Prefix string }
func (FuncKey) PrefixForClear ¶
type JsonEncoder ¶
type JsonEncoder[T any] struct{}
func (JsonEncoder[T]) DecodeValue ¶
func (j JsonEncoder[T]) DecodeValue(data []byte) (any, error)
func (JsonEncoder[T]) EncodeValue ¶
func (j JsonEncoder[T]) EncodeValue(k, v any) ([]byte, error)
type PutOptions ¶
type TextEncoder ¶
type TextEncoder struct{}
func (TextEncoder) DecodeValue ¶
func (t TextEncoder) DecodeValue(data []byte) (any, error)
func (TextEncoder) EncodeValue ¶
func (t TextEncoder) EncodeValue(k, v any) ([]byte, error)
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package sdcacheredis 使用redis实现的cache
|
Package sdcacheredis 使用redis实现的cache |
Package sdcacheristretto 使用ristretto实现的cache
|
Package sdcacheristretto 使用ristretto实现的cache |
Click to show internal directories.
Click to hide internal directories.