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

Method IncreaseCached

internal/utils/cachehits/stat.go:80–111  ·  view source on GitHub ↗
(category string)

Source from the content-addressed store, hash-verified

78}
79
80func (this *Stat) IncreaseCached(category string) {
81 this.mu.RLock()
82 var item = this.itemMap[category]
83 if item != nil {
84 if item.isGood || item.isBad {
85 this.mu.RUnlock()
86 return
87 }
88
89 atomic.AddUint64(&item.countCached, 1)
90 this.mu.RUnlock()
91 return
92 }
93 this.mu.RUnlock()
94
95 this.mu.Lock()
96
97 if len(this.itemMap) > this.maxItems {
98 // remove one randomly
99 for k := range this.itemMap {
100 delete(this.itemMap, k)
101 break
102 }
103 }
104
105 this.itemMap[category] = &Item{
106 countHits: 0,
107 countCached: 1,
108 timestamp: fasttime.Now().Unix(),
109 }
110 this.mu.Unlock()
111}
112
113func (this *Stat) IncreaseHit(category string) {
114 this.mu.RLock()

Callers 5

TestNewStatFunction · 0.80
TestNewStat_MemoryFunction · 0.80
BenchmarkStatFunction · 0.80
MatchStringCacheFunction · 0.80
MatchBytesCacheFunction · 0.80

Calls 6

NowFunction · 0.92
RLockMethod · 0.80
RUnlockMethod · 0.80
UnixMethod · 0.80
LockMethod · 0.45
UnlockMethod · 0.45

Tested by 3

TestNewStatFunction · 0.64
TestNewStat_MemoryFunction · 0.64
BenchmarkStatFunction · 0.64