kv

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 9, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KVErrorDefault          = 10000
	KVErrorNotFound         = 10001
	KVErrorKeyNotProvider   = 10002
	KVErrorGlobalNotProvide = 10003
	KVErrorCacheDefense     = 10004
)

Variables

View Source
var (
	ErrNotInit                = NewErrDefault("", "KV is not instantiated")
	ErrDataQueryerNotProvider = NewErrFn4GlobalNotProvider("the kv querier does not provided")

	DefaultKey   = "_kv_default_"
	NeverExpired = int64(-1)
)

Functions

This section is empty.

Types

type Cancel

type Cancel func() bool

type DataCheck

type DataCheck[K comparable, V any] func(map[K]V) error

type ErrCacheDefense

type ErrCacheDefense struct {
	// contains filtered or unexported fields
}

func NewErrCacheDefense

func NewErrCacheDefense(name, msg string) *ErrCacheDefense

func (*ErrCacheDefense) Code

func (e *ErrCacheDefense) Code() int64

func (*ErrCacheDefense) Error

func (e *ErrCacheDefense) Error() string

type ErrDefault

type ErrDefault struct {
	// contains filtered or unexported fields
}

func NewErrDefault

func NewErrDefault(name, msg string) *ErrDefault

func (*ErrDefault) Code

func (e *ErrDefault) Code() int64

func (*ErrDefault) Error

func (e *ErrDefault) Error() string

type ErrFn4GlobalNotProvider

type ErrFn4GlobalNotProvider struct {
	// contains filtered or unexported fields
}

func NewErrFn4GlobalNotProvider

func NewErrFn4GlobalNotProvider(name string) *ErrFn4GlobalNotProvider

func (*ErrFn4GlobalNotProvider) Code

func (e *ErrFn4GlobalNotProvider) Code() int64

func (*ErrFn4GlobalNotProvider) Error

func (e *ErrFn4GlobalNotProvider) Error() string

type ErrFn4KeyNotProvider

type ErrFn4KeyNotProvider struct {
	// contains filtered or unexported fields
}

func NewErrFn4KeyNotProvider

func NewErrFn4KeyNotProvider(name string) *ErrFn4KeyNotProvider

func (*ErrFn4KeyNotProvider) Code

func (e *ErrFn4KeyNotProvider) Code() int64

func (*ErrFn4KeyNotProvider) Error

func (e *ErrFn4KeyNotProvider) Error() string

type ErrKeyNotFound

type ErrKeyNotFound struct {
	// contains filtered or unexported fields
}

func NewErrKeyNotFound

func NewErrKeyNotFound(name string, key any) *ErrKeyNotFound

func (*ErrKeyNotFound) Code

func (e *ErrKeyNotFound) Code() int64

func (*ErrKeyNotFound) Error

func (e *ErrKeyNotFound) Error() string

type FetchGlobal

type FetchGlobal[K comparable, V any] func() (map[K]V, error)

type FetchKey

type FetchKey[K comparable, V any] func(K) (map[K]V, error)

type KV

type KV[K comparable, V any] interface {
	// 直接获取缓存
	GetCacheByKey(K) (V, KVError)

	// 获取缓存,如果没有命中则回源
	GetCacheOrElseSourceByKey(K) (V, KVError)

	// 直接获取缓存
	GetCache() (map[K]V, KVError)

	// 获取缓存,如果没有命中则回源
	GetCacheOrElseSource() (map[K]V, KVError)

	// 直接回源
	GetSourceByKey(K) (V, KVError)

	// 直接回源
	GetSource() (map[K]V, KVError)

	// 查询数据源,如果查询失败 则通过本地缓存兜底
	// 如果查询源数据失败,则走本地缓存。 error将返回ErrCacheDefense
	GetSourceOrElseCache() (map[K]V, KVError)

	// 查询数据源,如果查询失败 则通过本地缓存兜底
	// 如果查询源数据失败,则走本地缓存。 error将返回ErrCacheDefense
	GetSourceOrElseCacheByKey(K) (V, KVError)
}

func NewKV

func NewKV[K comparable, V any](opts ...OptionFn[K, V]) (KV[K, V], error)

type KVError

type KVError interface {
	error
	Code() int64
}

type MetricReport

type MetricReport func(kvEname, kvName string, err error)

type OptionFn

type OptionFn[K comparable, V any] func(c *simpleKV[K, V])

func WithDataCheck

func WithDataCheck[K comparable, V any](fn DataCheck[K, V]) OptionFn[K, V]

WithDataCheck 数据检查器

func WithEname

func WithEname[K comparable, V any](ename string) OptionFn[K, V]

WithEname KV英文名

func WithExpired

func WithExpired[K comparable, V any](expired int64) OptionFn[K, V]

WithExpired key的过期时间 默认表示不过期

func WithFetchGlobalQuery

func WithFetchGlobalQuery[K comparable, V any](fn FetchGlobal[K, V]) OptionFn[K, V]

WithFetchGlobalQuery 全局数据查询器

func WithFetchKeyQuery

func WithFetchKeyQuery[K comparable, V any](fn FetchKey[K, V]) OptionFn[K, V]

WithFetchKeyQuery 按key数据查询器

func WithInterval4FetchGlobal

func WithInterval4FetchGlobal[K comparable, V any](interval int) OptionFn[K, V]

WithInterval4FetchGlobal 指定周期更新 0表示不更新

func WithInterval4FetchKey

func WithInterval4FetchKey[K comparable, V any](interval int) OptionFn[K, V]

WithInterval4FetchKey 指定周期更新 0表示不更新

func WithMetricReport

func WithMetricReport[K comparable, V any](fn MetricReport) OptionFn[K, V]

func WithName

func WithName[K comparable, V any](name string) OptionFn[K, V]

WithName KV中文名

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳