Documentation
¶
Index ¶
- func DefaultKeyBuilder(ctx context.Context, name string, key any) string
- type Builder
- type CacheAdaptor
- type CacheManager
- func (l *CacheManager[K, V]) Del(ctx context.Context, key K) error
- func (l *CacheManager[K, V]) Get(ctx context.Context, key K) (result V, isCached bool, err error)
- func (l *CacheManager[K, V]) Load(ctx context.Context, key K, loader SingleDataLoader[K, V]) (r V, e error)
- func (l *CacheManager[K, V]) MDel(ctx context.Context, keys []K) (err error)
- func (l *CacheManager[K, V]) MGet(ctx context.Context, keys []K) (result map[K]V, err error)
- func (l *CacheManager[K, V]) MLoad(ctx context.Context, keys []K, loader MultiDataLoader[K, V]) (map[K]V, error)
- func (l *CacheManager[K, V]) MSet(ctx context.Context, kv map[K]V) (err error)
- func (l *CacheManager[K, V]) Set(ctx context.Context, k K, v V) error
- type CacheValue
- type Compressor
- type Config
- type Logger
- type Marshaller
- type Metrics
- type MultiDataLoader
- type Option
- func CacheNil(cacheNil bool) Option
- func KeyBuilder(f Builder) Option
- func SetCompressor(compressor Compressor) Option
- func SetLogger(logger Logger) Option
- func SetMarshaller(marshaller Marshaller) Option
- func SetMetrics(metrics Metrics) Option
- func TTL(ttl time.Duration, jitter time.Duration) Option
- func Version(version string) Option
- type SingleDataLoader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CacheAdaptor ¶
type CacheManager ¶
type CacheManager[K comparable, V any] struct { // contains filtered or unexported fields }
func NewCacheManager ¶
func NewCacheManager[K comparable, V any](name string, adaptor CacheAdaptor, opts ...Option) *CacheManager[K, V]
func (*CacheManager[K, V]) Get ¶
func (l *CacheManager[K, V]) Get(ctx context.Context, key K) (result V, isCached bool, err error)
func (*CacheManager[K, V]) Load ¶
func (l *CacheManager[K, V]) Load(ctx context.Context, key K, loader SingleDataLoader[K, V]) (r V, e error)
Load Cache-Aside 实现,单个查询
func (*CacheManager[K, V]) MDel ¶
func (l *CacheManager[K, V]) MDel(ctx context.Context, keys []K) (err error)
func (*CacheManager[K, V]) MGet ¶
func (l *CacheManager[K, V]) MGet(ctx context.Context, keys []K) (result map[K]V, err error)
func (*CacheManager[K, V]) MLoad ¶
func (l *CacheManager[K, V]) MLoad(ctx context.Context, keys []K, loader MultiDataLoader[K, V]) (map[K]V, error)
MLoad Cache-Aside 实现,批量查询,返回引用(返回的map中不会有为nil的value)
type CacheValue ¶
type Compressor ¶
type Logger ¶
type Logger interface {
Debug(ctx context.Context, message string, fields map[string]any)
Info(ctx context.Context, message string, fields map[string]any)
Warn(ctx context.Context, message string, fields map[string]any)
Error(ctx context.Context, message string, fields map[string]any)
}
Logger 日志接口
func NewNoopLogger ¶
func NewNoopLogger() Logger
type Marshaller ¶
type Metrics ¶
type Metrics interface {
Counter(ctx context.Context, name string, inc float64, labels map[string]string)
Timer(ctx context.Context, name string, seconds float64, labels map[string]string)
Value(ctx context.Context, name string, value float64, labels map[string]string)
}
Metrics 监控埋点接口
func NewNoopMetrics ¶
func NewNoopMetrics() Metrics
type MultiDataLoader ¶
type MultiDataLoader[K comparable, V any] func(keys []K) (map[K]V, error)
type Option ¶
type Option func(*Config)
func KeyBuilder ¶
func SetCompressor ¶
func SetCompressor(compressor Compressor) Option
func SetMarshaller ¶
func SetMarshaller(marshaller Marshaller) Option
func SetMetrics ¶
type SingleDataLoader ¶
type SingleDataLoader[K comparable, V any] func(k K) (V, error)
Click to show internal directories.
Click to hide internal directories.