Documentation
¶
Index ¶
- Constants
- Variables
- type Cancel
- type DataCheck
- type ErrCacheDefense
- type ErrDefault
- type ErrFn4GlobalNotProvider
- type ErrFn4KeyNotProvider
- type ErrKeyNotFound
- type FetchGlobal
- type FetchKey
- type KV
- type KVError
- type MetricReport
- type OptionFn
- func WithDataCheck[K comparable, V any](fn DataCheck[K, V]) OptionFn[K, V]
- func WithEname[K comparable, V any](ename string) OptionFn[K, V]
- func WithExpired[K comparable, V any](expired int64) OptionFn[K, V]
- func WithFetchGlobalQuery[K comparable, V any](fn FetchGlobal[K, V]) OptionFn[K, V]
- func WithFetchKeyQuery[K comparable, V any](fn FetchKey[K, V]) OptionFn[K, V]
- func WithInterval4FetchGlobal[K comparable, V any](interval int) OptionFn[K, V]
- func WithInterval4FetchKey[K comparable, V any](interval int) OptionFn[K, V]
- func WithMetricReport[K comparable, V any](fn MetricReport) OptionFn[K, V]
- func WithName[K comparable, V any](name string) OptionFn[K, V]
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 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
type ErrDefault ¶
type ErrDefault struct {
// contains filtered or unexported fields
}
func NewErrDefault ¶
func NewErrDefault(name, msg string) *ErrDefault
type ErrFn4GlobalNotProvider ¶
type ErrFn4GlobalNotProvider struct {
// contains filtered or unexported fields
}
func NewErrFn4GlobalNotProvider ¶
func NewErrFn4GlobalNotProvider(name string) *ErrFn4GlobalNotProvider
type ErrFn4KeyNotProvider ¶
type ErrFn4KeyNotProvider struct {
// contains filtered or unexported fields
}
func NewErrFn4KeyNotProvider ¶
func NewErrFn4KeyNotProvider(name string) *ErrFn4KeyNotProvider
type ErrKeyNotFound ¶
type ErrKeyNotFound struct {
// contains filtered or unexported fields
}
func NewErrKeyNotFound ¶
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) }
type MetricReport ¶
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 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]
Click to show internal directories.
Click to hide internal directories.