MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / GC

Method GC

internal/stats/user_agent_parser.go:129–146  ·  view source on GitHub ↗

GC 回收多余的缓存

()

Source from the content-addressed store, hash-verified

127
128// GC 回收多余的缓存
129func (this *UserAgentParser) GC() {
130 var total = this.Len()
131 if total > this.maxCacheItems {
132 for {
133 var shardingIndex = this.gcIndex
134
135 this.mu.Lock(shardingIndex)
136 total -= len(this.cacheMaps[shardingIndex])
137 this.cacheMaps[shardingIndex] = map[uint64]UserAgentParserResult{}
138 this.gcIndex = (this.gcIndex + 1) % userAgentShardingCount
139 this.mu.Unlock(shardingIndex)
140
141 if total <= this.maxCacheItems {
142 break
143 }
144 }
145 }
146}

Callers 1

initMethod · 0.95

Calls 3

LenMethod · 0.95
LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected