change package name
This commit is contained in:
parent
42d2795a05
commit
928a608878
|
@ -15,6 +15,7 @@ var ctx = context.Background()
|
||||||
var mapFlush = safety.NewMap[string, func(any)]()
|
var mapFlush = safety.NewMap[string, func(any)]()
|
||||||
var getSingleFn = safety.NewMap[string, func(context.Context, any, time.Duration, ...any) (any, error)]()
|
var getSingleFn = safety.NewMap[string, func(context.Context, any, time.Duration, ...any) (any, error)]()
|
||||||
var getBatchFn = safety.NewMap[string, func(context.Context, any, time.Duration, ...any) (any, error)]()
|
var getBatchFn = safety.NewMap[string, func(context.Context, any, time.Duration, ...any) (any, error)]()
|
||||||
|
var getBatchToMapFn = safety.NewMap[string, func(context.Context, any, time.Duration, ...any) (any, error)]()
|
||||||
var anyFlush = safety.NewMap[string, func()]()
|
var anyFlush = safety.NewMap[string, func()]()
|
||||||
|
|
||||||
var getVar = safety.NewMap[string, func(context.Context, time.Duration, ...any) (any, error)]()
|
var getVar = safety.NewMap[string, func(context.Context, time.Duration, ...any) (any, error)]()
|
||||||
|
@ -94,6 +95,13 @@ func pushFlushMap[K comparable, V any](m *cache.MapCache[K, V], args ...any) {
|
||||||
}
|
}
|
||||||
return m.GetCacheBatch(ct, kk, t, a...)
|
return m.GetCacheBatch(ct, kk, t, a...)
|
||||||
})
|
})
|
||||||
|
getBatchToMapFn.Store(name, func(ct context.Context, k any, t time.Duration, a ...any) (any, error) {
|
||||||
|
kk, ok := k.([]K)
|
||||||
|
if !ok {
|
||||||
|
return nil, errors.New(str.Join("cache ", name, " key type err"))
|
||||||
|
}
|
||||||
|
return m.GetBatchToMap(ct, kk, t, a...)
|
||||||
|
})
|
||||||
FlushPush()
|
FlushPush()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,6 +133,20 @@ func GetMultiple[T, K any](name string, ct context.Context, key []K, timeout tim
|
||||||
r = vv.([]T)
|
r = vv.([]T)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
func GetMultipleToMap[T any, K comparable](name string, ct context.Context, key []K, timeout time.Duration, params ...any) (r map[K]T, err error) {
|
||||||
|
ct = context.WithValue(ct, "getCache", name)
|
||||||
|
v, ok := getBatchToMapFn.Load(name)
|
||||||
|
if !ok {
|
||||||
|
err = errors.New(str.Join("cache ", name, " doesn't exist"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
vv, err := v(ct, key, timeout, params...)
|
||||||
|
if err != nil {
|
||||||
|
return r, err
|
||||||
|
}
|
||||||
|
r = vv.(map[K]T)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func parseArgs(args ...any) (string, func() time.Duration) {
|
func parseArgs(args ...any) (string, func() time.Duration) {
|
||||||
var name string
|
var name string
|
Loading…
Reference in New Issue
Block a user