-
Notifications
You must be signed in to change notification settings - Fork 0
/
cache.go
69 lines (56 loc) · 1.21 KB
/
cache.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package validate
/*
// TODO: idea for optimize ...
// - use pool for Validation
// - cache struct reflect value
// Usage:
// // use a single instance of Validate, it caches struct info
// vf := validate.NewFactory()
// v := vf.New(data)
// v.Validate()
// global factory for create Validation
var gf = newFactory()
// factory for create Validation instances
type factory struct {
// pool for Validation instances
pool sync.Pool
// m atomic.Value // map[reflect.Type]*cStruct
}
func newFactory() *factory {
f := &factory{}
f.pool.New = func() any {
return newValidation(nil)
}
return f
}
func (f *factory) get() *Validation {
v := f.pool.Get().(*Validation)
// TODO clear something
return v
}
func (f *factory) put(v *Validation) {
f.pool.Put(v)
}
*/
// func test() {
// i32 := driver.Int32
// fmt.Println(i32)
// }
/*
// TODO cache struct reflect value, tags and more
type structMeta struct {
}
type cache struct {
m sync.Map
// m atomic.Value
// map[reflect.Type]*cStruct
}
func (c *cache) get(rt reflect.Type) *structMeta {
// key := rt.PkgPath() + rt.Name()
return c.m.Load(rt)
}
func (c *cache) set(rt reflect.Type, meta structMeta) {
// key := rt.PkgPath() + rt.Name()
c.m.Store(rt, data)
}
*/