• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

yyle88 / gormcls / 13872499119

15 Mar 2025 11:40AM UTC coverage: 33.333% (-15.8%) from 49.153%
13872499119

push

github

yangyile
这个项目名字不太符合repo的含义就把repo独立到新项目里

9 of 16 new or added lines in 3 files covered. (56.25%)

39 of 117 relevant lines covered (33.33%)

0.92 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/gormclasscache/gorm_class_cache.go
1
package gormclasscache
2

3
import (
4
        "sync"
5

6
        "github.com/yyle88/erero"
7
        "github.com/yyle88/gormcls/gormmodelclass"
8
        "github.com/yyle88/mutexmap"
9
        "github.com/yyle88/mutexmap/cachemap"
10
)
11

12
// UmcV1 提供缓存功能,避免每次都调用 Columns 函数生成 gormcnm 对象,提升性能
13
// UmcV1 provides caching functionality, avoiding the need to call the Columns function to generate gormcnm objects each time, thus improving performance.
NEW
14
func UmcV1[MOD gormmodelclass.ClassType[CLS], CLS any](a MOD, cache *cachemap.Map[string, interface{}]) (MOD, CLS) {
×
15
        vax, _ := cache.Getset(a.TableName(), func() (interface{}, error) {
×
16
                return a.Columns(), nil
×
17
        })
×
18
        cls, ok := vax.(CLS)
×
19
        if !ok {
×
20
                panic(erero.Errorf("wrong TABLE_NAME=%s", a.TableName()))
×
21
        }
22
        return a, cls
×
23
}
24

25
// UmcV2 提供缓存功能,避免每次都调用 Columns 函数生成 gormcnm 对象,提升性能
26
// UmcV2 provides caching functionality, avoiding the need to call the Columns function to generate gormcnm objects each time, thus improving performance.
NEW
27
func UmcV2[MOD gormmodelclass.ClassType[CLS], CLS any](a MOD, cache *mutexmap.Map[string, interface{}]) (MOD, CLS) {
×
28
        vax, _ := cache.Getset(a.TableName(), func() interface{} {
×
29
                return a.Columns()
×
30
        })
×
31
        cls, ok := vax.(CLS)
×
32
        if !ok {
×
33
                panic(erero.Errorf("wrong TABLE_NAME=%s", a.TableName()))
×
34
        }
35
        return a, cls
×
36
}
37

38
// UmcV3 提供缓存功能,避免每次都调用 Columns 函数生成 gormcnm 对象,提升性能
39
// UmcV3 provides caching functionality, avoiding the need to call the Columns function to generate gormcnm objects each time, thus improving performance.
NEW
40
func UmcV3[MOD gormmodelclass.ClassType[CLS], CLS any](a MOD, cache *sync.Map) (MOD, CLS) {
×
41
        value, ok := cache.Load(a.TableName())
×
42
        if !ok {
×
43
                value = a.Columns()
×
44
                cache.Store(a.TableName(), value) //这里在并发时有可能多次存储,但是这并不影响任何功能,因此忽略这个情况
×
45
        }
×
46
        cls, ok := value.(CLS)
×
47
        if !ok {
×
48
                panic(erero.Errorf("wrong TABLE_NAME=%s", a.TableName()))
×
49
        }
50
        return a, cls
×
51
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc