File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,7 +15,32 @@ var SemanticVersionRegex = regexp.MustCompile(`^(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:
1515var simpleNumericRegex = regexp .MustCompile (`^\d+$` )
1616
1717// versionCache caches parsed versions to avoid re-parsing the same strings.
18- var versionCache sync.Map
18+ var versionCache = & boundedCache {
19+ items : make (map [string ]* VersionInfo ),
20+ max : 10000 ,
21+ }
22+
23+ type boundedCache struct {
24+ mu sync.RWMutex
25+ items map [string ]* VersionInfo
26+ max int
27+ }
28+
29+ func (c * boundedCache ) Load (key string ) (* VersionInfo , bool ) {
30+ c .mu .RLock ()
31+ v , ok := c .items [key ]
32+ c .mu .RUnlock ()
33+ return v , ok
34+ }
35+
36+ func (c * boundedCache ) Store (key string , value * VersionInfo ) {
37+ c .mu .Lock ()
38+ if len (c .items ) >= c .max {
39+ c .items = make (map [string ]* VersionInfo )
40+ }
41+ c .items [key ] = value
42+ c .mu .Unlock ()
43+ }
1944
2045// VersionInfo represents a parsed version with its components.
2146type VersionInfo struct {
@@ -35,7 +60,7 @@ func ParseVersion(s string) (*VersionInfo, error) {
3560
3661 // Check cache first
3762 if cached , ok := versionCache .Load (s ); ok {
38- return cached .( * VersionInfo ) , nil
63+ return cached , nil
3964 }
4065
4166 v := & VersionInfo {Original : s }
You can’t perform that action at this time.
0 commit comments